Submission #260954

# Submission time Handle Problem Language Result Execution time Memory
260954 2020-08-11T08:28:01 Z 임성재(#5066) Harvest (JOI20_harvest) C++17
5 / 100
5000 ms 71544 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define em emplace
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int inf = 1e9;

int n, m, q;
ll l, c;
ll a[200010];
ll b[200010];
int nxt[200010];
int g[200010];
ll cost[200010];
bool chk[3010];
ll t[200010];
vector<pll> v;
ll dist[3010][3010];

int main() {
	fast;

	cin >> n >> m >> l >> c;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
		t[i] = INF;
	}

	for(int i=1; i<=n; i++) {
		ll t = a[i] - c;

		t = t % l + l;

		nxt[i] = upper_bound(a+1, a+n+1, t % l) - a - 1;
		if(nxt[i] == 0) nxt[i] = n;
		
		cost[i] = (c - (a[i] - a[nxt[i]])) / l * l + (a[i] - a[nxt[i]]);
		while(cost[i] < c) cost[i] += l;
		while(cost[i] >= c+l) cost[i] -= l;
	}

	for(int i=1; i<=n; i++) {
		int j, cnt = 0;
		t[i] = cost[i];
		for(j=nxt[i]; j != i && cnt <= n; j = nxt[j], cnt++) 
			t[i] += cost[j];

		if(j != i) t[i] = INF;
	}

	for(int i=1; i<=m; i++) {
		cin >> b[i];

		int k = upper_bound(a+1, a+n+1, b[i]) - a - 1;
		if(k == 0) k = n;
		
		ll d = b[i] - a[k];
		if(d < 0) d += l;

		g[i] = k;

		for(int j = k; !dist[i][j]; j = nxt[j]) {
			dist[i][j] = d;

			d += cost[j];
		}
	}

	cin >> q;

	for(int i=1; i<=q; i++) {
		int v;
		ll T, ans = 0;
		cin >> v >> T;

		for(int j=1; j<=m; j++) {
			if(dist[j][v] <= T && dist[j][v] != 0) {
				ans += (T - dist[j][v]) / t[v] + 1;
			}
		}

		cout << ans << "\n";
	}
} 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 128 ms 12672 KB Output is correct
3 Correct 120 ms 12672 KB Output is correct
4 Correct 232 ms 71292 KB Output is correct
5 Correct 203 ms 46624 KB Output is correct
6 Correct 225 ms 46584 KB Output is correct
7 Correct 252 ms 46840 KB Output is correct
8 Correct 157 ms 22652 KB Output is correct
9 Correct 158 ms 22648 KB Output is correct
10 Correct 163 ms 23056 KB Output is correct
11 Correct 198 ms 22904 KB Output is correct
12 Correct 257 ms 71328 KB Output is correct
13 Correct 340 ms 71544 KB Output is correct
14 Correct 233 ms 71288 KB Output is correct
15 Correct 212 ms 47480 KB Output is correct
16 Correct 207 ms 47608 KB Output is correct
17 Correct 197 ms 47156 KB Output is correct
18 Correct 190 ms 30632 KB Output is correct
19 Correct 174 ms 30584 KB Output is correct
20 Correct 207 ms 30128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5043 ms 14712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 128 ms 12672 KB Output is correct
3 Correct 120 ms 12672 KB Output is correct
4 Correct 232 ms 71292 KB Output is correct
5 Correct 203 ms 46624 KB Output is correct
6 Correct 225 ms 46584 KB Output is correct
7 Correct 252 ms 46840 KB Output is correct
8 Correct 157 ms 22652 KB Output is correct
9 Correct 158 ms 22648 KB Output is correct
10 Correct 163 ms 23056 KB Output is correct
11 Correct 198 ms 22904 KB Output is correct
12 Correct 257 ms 71328 KB Output is correct
13 Correct 340 ms 71544 KB Output is correct
14 Correct 233 ms 71288 KB Output is correct
15 Correct 212 ms 47480 KB Output is correct
16 Correct 207 ms 47608 KB Output is correct
17 Correct 197 ms 47156 KB Output is correct
18 Correct 190 ms 30632 KB Output is correct
19 Correct 174 ms 30584 KB Output is correct
20 Correct 207 ms 30128 KB Output is correct
21 Execution timed out 5043 ms 14712 KB Time limit exceeded
22 Halted 0 ms 0 KB -