Submission #29399

# Submission time Handle Problem Language Result Execution time Memory
29399 2017-07-19T08:45:28 Z cdemirer Semiexpress (JOI17_semiexpress) C++14
100 / 100
0 ms 2224 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<pair<int, int> > > vvii;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

ll N, M, K;
ll A, B, C;
ll T;
ll S[3000];
ll ans = 0;

ll ng;
ll gsz[3000];
ll gbudget[3000];
set<llp> SS;

void update(int x) {
	ll slowrlim = gbudget[x] / A;
	if (slowrlim +1> gsz[x]) {
		ans += gsz[x];
		return;
	}
	ans += slowrlim + 1;
	ll ptr = slowrlim + 1;
	if (ptr >= gsz[x]) return;
	if (gbudget[x] - ptr*C < 0) {
		return;
	}
	ll semirlim = (gbudget[x]-ptr*C) / A;
	if (ptr + semirlim +1 > gsz[x]) semirlim = gsz[x]-ptr-1;
	SS.insert(mp(semirlim+1, x));
}

void advance(int x) {
	ll ptr = gbudget[x] / A + 1;
	gsz[x] -= ptr;
	//cerr << "Semi added to group " << x << endl;
	gbudget[x] -= ptr*C;
	update(x);
}
	

int main(int argc, char **argv) {

	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);

	scanf("%lld%lld%lld", &N, &M, &K);
	scanf("%lld%lld%lld", &A, &B, &C);
	scanf("%lld", &T);
	for (int i = 0; i < M; i++) {
		scanf("%lld", &(S[i]));
	}
	ng = M-1;
	for (int i = 0; i < ng; i++) {
		gsz[i] = S[i+1]-S[i];
		gbudget[i] = T - (S[i]-1)*B;
		if (gbudget[i] < 0) {
			ng = i;
			break;
		}
	}
	for (int i = 0; i < ng; i++) {
		update(i);
	}
	K -= M;
	while (K-- && SS.size() > 0) {
		set<llp>::iterator it = SS.end(); it--;
		llp x = *it;
		SS.erase(it);
		advance(x.second);
	}
	ans -= 1;
	if (T - (S[M-1]-1) * B >= 0) ans += 1;
	printf("%lld\n", ans);

	return 0;
}

Compilation message

semiexpress.cpp: In function 'int main(int, char**)':
semiexpress.cpp:55:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &N, &M, &K);
                                   ^
semiexpress.cpp:56:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &A, &B, &C);
                                   ^
semiexpress.cpp:57:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &T);
                   ^
semiexpress.cpp:59:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &(S[i]));
                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2092 KB Output is correct
2 Correct 0 ms 2092 KB Output is correct
3 Correct 0 ms 2092 KB Output is correct
4 Correct 0 ms 2092 KB Output is correct
5 Correct 0 ms 2092 KB Output is correct
6 Correct 0 ms 2092 KB Output is correct
7 Correct 0 ms 2092 KB Output is correct
8 Correct 0 ms 2092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2092 KB Output is correct
2 Correct 0 ms 2092 KB Output is correct
3 Correct 0 ms 2092 KB Output is correct
4 Correct 0 ms 2092 KB Output is correct
5 Correct 0 ms 2092 KB Output is correct
6 Correct 0 ms 2092 KB Output is correct
7 Correct 0 ms 2092 KB Output is correct
8 Correct 0 ms 2092 KB Output is correct
9 Correct 0 ms 2092 KB Output is correct
10 Correct 0 ms 2092 KB Output is correct
11 Correct 0 ms 2092 KB Output is correct
12 Correct 0 ms 2092 KB Output is correct
13 Correct 0 ms 2092 KB Output is correct
14 Correct 0 ms 2092 KB Output is correct
15 Correct 0 ms 2092 KB Output is correct
16 Correct 0 ms 2092 KB Output is correct
17 Correct 0 ms 2092 KB Output is correct
18 Correct 0 ms 2092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2092 KB Output is correct
2 Correct 0 ms 2092 KB Output is correct
3 Correct 0 ms 2092 KB Output is correct
4 Correct 0 ms 2092 KB Output is correct
5 Correct 0 ms 2092 KB Output is correct
6 Correct 0 ms 2092 KB Output is correct
7 Correct 0 ms 2092 KB Output is correct
8 Correct 0 ms 2092 KB Output is correct
9 Correct 0 ms 2092 KB Output is correct
10 Correct 0 ms 2092 KB Output is correct
11 Correct 0 ms 2092 KB Output is correct
12 Correct 0 ms 2092 KB Output is correct
13 Correct 0 ms 2092 KB Output is correct
14 Correct 0 ms 2092 KB Output is correct
15 Correct 0 ms 2092 KB Output is correct
16 Correct 0 ms 2092 KB Output is correct
17 Correct 0 ms 2092 KB Output is correct
18 Correct 0 ms 2092 KB Output is correct
19 Correct 0 ms 2092 KB Output is correct
20 Correct 0 ms 2092 KB Output is correct
21 Correct 0 ms 2092 KB Output is correct
22 Correct 0 ms 2092 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 0 ms 2092 KB Output is correct
26 Correct 0 ms 2092 KB Output is correct
27 Correct 0 ms 2224 KB Output is correct
28 Correct 0 ms 2224 KB Output is correct
29 Correct 0 ms 2092 KB Output is correct
30 Correct 0 ms 2092 KB Output is correct