답안 #67626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67626 2018-08-15T06:54:36 Z 검수컵(#1978, imsifile) 코코넛 젤리 음료수 (FXCUP3_nectar) C++
100 / 100
570 ms 1452 KB
#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 3 ms 256 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 4 ms 608 KB Output is correct
8 Correct 5 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 4 ms 608 KB Output is correct
8 Correct 5 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 13 ms 792 KB Output is correct
11 Correct 19 ms 820 KB Output is correct
12 Correct 44 ms 884 KB Output is correct
13 Correct 89 ms 1292 KB Output is correct
14 Correct 17 ms 1292 KB Output is correct
15 Correct 18 ms 1292 KB Output is correct
16 Correct 18 ms 1292 KB Output is correct
17 Correct 570 ms 1292 KB Output is correct
18 Correct 154 ms 1324 KB Output is correct
19 Correct 70 ms 1452 KB Output is correct
20 Correct 58 ms 1452 KB Output is correct
21 Correct 13 ms 1452 KB Output is correct
22 Correct 46 ms 1452 KB Output is correct
23 Correct 16 ms 1452 KB Output is correct