답안 #682402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682402 2023-01-16T08:07:59 Z iskhakkutbilim Bootfall (IZhO17_bootfall) C++14
13 / 100
1000 ms 308 KB
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 500;
const int S = 500 * 500;
int dp[S+1];
main(){
	int n; cin >> n;
	vector<int> a(n);
	int sum = 0, even = 0, odd = 0;
	for(int i = 0;i < n; i++){
		cin >> a[i];
		odd+= (a[i]%2==1);
		even+= (a[i]%2==0);
		sum+= a[i];
	}
	if(even > 0 and odd > 0){
		cout << 0;
		return 0;
	}
	if(sum%2==1){
		cout << 0;
		return 0;
	}
	vector<int> can;
	for(int tima = 1; tima <= 1000; tima++){
		sum+= tima;
		int ok = 1;
		for(int i = 0;i < a.size(); i++){
			if((sum-a[i])%2==1){
				ok = 0;
				break;
			}
		}
		if(ok) can.push_back(tima);
		sum-= tima;
	}
	
	
	vector<int> answer;
	for(int tima : can){
		sum+= tima;
		a.push_back(tima);
		int ok = 1;
		for(int i = 0;i < a.size(); i++){
			for(int s = 1; s <= (sum - a[i]) / 2; s++) dp[s] = 0;
			dp[0] = 1;
			for(int j = 0; j < a.size(); j++){
				if(i == j) continue;
				for(int s = (sum - a[i]) / 2; s >= 0; s--){
					if(s >= a[j]){
						dp[s] = max(dp[s], dp[s-a[j]]);
					}
				}
			}
			if(dp[(sum - a[i]) / 2] == 0){
				ok = 0;
				break;
			}
		}
		if(ok){
			answer.push_back(tima);
		}
		sum-= tima;
		a.pop_back();
	}
	cout << answer.size() << '\n';
	for(int x : answer) cout << x << ' ';
	return 0;
}

Compilation message

bootfall.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for(int i = 0;i < a.size(); i++){
      |                 ~~^~~~~~~~~~
bootfall.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int i = 0;i < a.size(); i++){
      |                 ~~^~~~~~~~~~
bootfall.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for(int j = 0; j < a.size(); j++){
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 16 ms 212 KB Output is correct
11 Correct 36 ms 296 KB Output is correct
12 Correct 13 ms 304 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 37 ms 284 KB Output is correct
15 Correct 28 ms 212 KB Output is correct
16 Correct 36 ms 304 KB Output is correct
17 Correct 11 ms 212 KB Output is correct
18 Correct 20 ms 308 KB Output is correct
19 Correct 17 ms 308 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 16 ms 212 KB Output is correct
11 Correct 36 ms 296 KB Output is correct
12 Correct 13 ms 304 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 37 ms 284 KB Output is correct
15 Correct 28 ms 212 KB Output is correct
16 Correct 36 ms 304 KB Output is correct
17 Correct 11 ms 212 KB Output is correct
18 Correct 20 ms 308 KB Output is correct
19 Correct 17 ms 308 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
21 Execution timed out 1066 ms 288 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 16 ms 212 KB Output is correct
11 Correct 36 ms 296 KB Output is correct
12 Correct 13 ms 304 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 37 ms 284 KB Output is correct
15 Correct 28 ms 212 KB Output is correct
16 Correct 36 ms 304 KB Output is correct
17 Correct 11 ms 212 KB Output is correct
18 Correct 20 ms 308 KB Output is correct
19 Correct 17 ms 308 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
21 Execution timed out 1066 ms 288 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 16 ms 212 KB Output is correct
11 Correct 36 ms 296 KB Output is correct
12 Correct 13 ms 304 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 37 ms 284 KB Output is correct
15 Correct 28 ms 212 KB Output is correct
16 Correct 36 ms 304 KB Output is correct
17 Correct 11 ms 212 KB Output is correct
18 Correct 20 ms 308 KB Output is correct
19 Correct 17 ms 308 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
21 Execution timed out 1066 ms 288 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 29 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 36 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 16 ms 212 KB Output is correct
11 Correct 36 ms 296 KB Output is correct
12 Correct 13 ms 304 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 37 ms 284 KB Output is correct
15 Correct 28 ms 212 KB Output is correct
16 Correct 36 ms 304 KB Output is correct
17 Correct 11 ms 212 KB Output is correct
18 Correct 20 ms 308 KB Output is correct
19 Correct 17 ms 308 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
21 Execution timed out 1066 ms 288 KB Time limit exceeded
22 Halted 0 ms 0 KB -