Submission #2891723


Source Code Expand

#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<cassert>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン!!!!
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad=座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正)
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m, r, t;
int a[5000][5000];
E b[5000];
vector<int>c[5000];
vector<B>e[5000];
signed main() {
	cin >> n >> m >> r >> t;
	for (int i = 0; i < m; i++) {
		cin >> b[i].from >> b[i].to >> b[i].cost;
		e[b[i].from].push_back(B{ b[i].to,b[i].cost });
		e[b[i].to].push_back(B{ b[i].from,b[i].cost });
	}
	priority_queue<P, vector<P>, greater<P>>p;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			a[i][j] = inf;
		a[i][i] = 0;
		p.push(P{ i,0 });
		while (!p.empty()) {
			P t = p.top(); p.pop();
			for (int j = 0; j < e[t.pos].size(); j++) {
				if (a[i][e[t.pos][j].to] > a[i][t.pos] + e[t.pos][j].cost) {
					a[i][e[t.pos][j].to] = a[i][t.pos] + e[t.pos][j].cost;
					p.push(P{ e[t.pos][j].to,a[i][e[t.pos][j].to] });
				}
			}
		}
		for (int j = 1; j <= n; j++) {
			c[i].push_back(a[i][j]);
		}
		sort(all(c[i]));
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			ld o = (ld)a[i][j] / t*r;
			if (o == floor(o)) o += 1;
			else o = ceil(o);
			int u = c[i].size() - (lower_bound(all(c[i]), o) - c[i].begin());
			if (r < t) u--;
			if (u > 0) ans += u;
			u = c[j].size() - (lower_bound(all(c[j]), o) - c[j].begin());
			if (r < t) u--;
			if (u > 0) ans += u;
		}
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task C - ウサギとカメ
User Thistle
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3527 Byte
Status AC
Exec Time 1758 ms
Memory 156800 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 18
Set Name Test Cases
Sample subtask0_sample-01.txt, subtask0_sample-02.txt
All subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt
Case Name Status Exec Time Memory
subtask0_sample-01.txt AC 3 ms 768 KB
subtask0_sample-02.txt AC 1 ms 512 KB
subtask1_01.txt AC 1 ms 512 KB
subtask1_02.txt AC 1 ms 640 KB
subtask1_03.txt AC 2 ms 640 KB
subtask1_04.txt AC 1 ms 512 KB
subtask1_05.txt AC 8 ms 7296 KB
subtask1_06.txt AC 11 ms 7296 KB
subtask1_07.txt AC 34 ms 12416 KB
subtask1_08.txt AC 41 ms 16896 KB
subtask1_09.txt AC 348 ms 68864 KB
subtask1_10.txt AC 360 ms 75520 KB
subtask1_11.txt AC 141 ms 38272 KB
subtask1_12.txt AC 1623 ms 156800 KB
subtask1_13.txt AC 1582 ms 156800 KB
subtask1_14.txt AC 1680 ms 156800 KB
subtask1_15.txt AC 814 ms 111488 KB
subtask1_16.txt AC 1758 ms 156800 KB