#include<stdio.h>
#include<vector>
using namespace std;
typedef long long lld;
struct rle {
int a, rpt;
rle(int a_=0, int rpt_=0) : a(a_), rpt(rpt_) {}
};
int N, J, R, T;
vector<rle> v[2];
lld sum;
int ce(int a){ return (a+R-1)/R; }
void push(int ix, rle k){
if(k.rpt == 0) return;
if(v[ix].empty()){ v[ix].push_back(k); return; }
int last=v[ix].size()-1;
if(v[ix][last].a == k.a) v[ix][last].rpt += k.rpt;
else v[ix].push_back(k);
}
int main(){
scanf("%d%d%d%d", &N, &J, &R, &T);
if(N==1){ printf("%d\n", J); return 0; }
push(0, rle(J, N-1)), sum=J;
int cur=0;
for(int i=T; i--;){
if(v[cur].size() == 1 && v[cur][0].a == 0) break;
sum += ce(v[cur][0].a);
for(int j=0; j<v[cur].size(); j++){
rle r = v[cur][j]; int com = 0;
if(j<v[cur].size()-1) com=v[cur][j+1].a;
push(cur^1, rle(r.a, r.rpt-1));
push(cur^1, rle(r.a-ce(r.a)+ce(com), 1));
}
v[cur].clear(); cur^=1;
}
for(int i=v[cur].size(); i--;){
for(int j=v[cur][i].rpt; j--;) printf("%d\n", v[cur][i].a);
}
printf("%lld\n", sum);
return 0;
}
Compilation message
nectar.cpp: In function 'int main()':
nectar.cpp:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<v[cur].size(); j++){
~^~~~~~~~~~~~~~
nectar.cpp:35:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j<v[cur].size()-1) com=v[cur][j+1].a;
~^~~~~~~~~~~~~~~~
nectar.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &N, &J, &R, &T);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
536 KB |
Output is correct |
7 |
Correct |
3 ms |
564 KB |
Output is correct |
8 |
Correct |
7 ms |
564 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
536 KB |
Output is correct |
7 |
Correct |
3 ms |
564 KB |
Output is correct |
8 |
Correct |
7 ms |
564 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
19 ms |
612 KB |
Output is correct |
11 |
Correct |
20 ms |
852 KB |
Output is correct |
12 |
Correct |
51 ms |
900 KB |
Output is correct |
13 |
Correct |
89 ms |
1284 KB |
Output is correct |
14 |
Correct |
25 ms |
1284 KB |
Output is correct |
15 |
Correct |
20 ms |
1284 KB |
Output is correct |
16 |
Correct |
18 ms |
1284 KB |
Output is correct |
17 |
Correct |
566 ms |
1284 KB |
Output is correct |
18 |
Correct |
201 ms |
1328 KB |
Output is correct |
19 |
Correct |
110 ms |
1452 KB |
Output is correct |
20 |
Correct |
58 ms |
1456 KB |
Output is correct |
21 |
Correct |
14 ms |
1492 KB |
Output is correct |
22 |
Correct |
47 ms |
1492 KB |
Output is correct |
23 |
Correct |
20 ms |
1492 KB |
Output is correct |