답안 #418382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418382 2021-06-05T10:29:24 Z ismoilov 쌀 창고 (IOI11_ricehub) C++14
100 / 100
16 ms 2164 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
deque <int> fir, sec;
ll sum_fir, sum_sec;

ll check(){
	int ans;
	if(sec.size() == fir.size())
		ans = sec.front();
	else
		ans = fir.back();
	ll c = sum_sec - sum_fir;
	c += (ll) ans * fir.size();
	c -= (ll) ans * sec.size();
	return c;
}

int besthub(int r, int l, int X[], ll b){
	int ans = 0;
	fp(i,0,r){
		sec.push_back(X[i]);
		sum_sec += X[i];
		if(fir.size() < sec.size()){
			sum_sec -= sec.front();
			sum_fir += sec.front();
			fir.push_back(sec.front());
			sec.pop_front();
		}
		
		while(b < check()){
			if(fir.empty()){
				sum_sec -= sec.back();
				sec.pop_back();
			}
			else{
				sum_fir -= fir.front();
				fir.pop_front();
			}
			
			if(fir.size() < sec.size()){
				sum_sec -= sec.front();
				sum_fir += sec.front();
				fir.push_back(sec.front());
				sec.pop_front();
			}
		}
		ans = max(ans, (int) fir.size() + (int) sec.size());
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
ricehub.cpp:28:2: note: in expansion of macro 'fp'
   28 |  fp(i,0,r){
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 16 ms 1484 KB Output is correct
4 Correct 16 ms 2124 KB Output is correct
5 Correct 7 ms 844 KB Output is correct
6 Correct 9 ms 836 KB Output is correct
7 Correct 15 ms 1832 KB Output is correct
8 Correct 15 ms 1868 KB Output is correct
9 Correct 7 ms 716 KB Output is correct
10 Correct 7 ms 716 KB Output is correct
11 Correct 16 ms 2084 KB Output is correct
12 Correct 16 ms 2164 KB Output is correct
13 Correct 8 ms 844 KB Output is correct
14 Correct 8 ms 844 KB Output is correct
15 Correct 12 ms 1668 KB Output is correct
16 Correct 12 ms 1632 KB Output is correct
17 Correct 14 ms 1952 KB Output is correct
18 Correct 14 ms 1868 KB Output is correct
19 Correct 15 ms 1960 KB Output is correct
20 Correct 15 ms 1976 KB Output is correct