답안 #754296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754296 2023-06-07T12:27:01 Z Olympia Bootfall (IZhO17_bootfall) C++17
13 / 100
1000 ms 324 KB
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <map>
#include <bitset>
#include <set>
#include <stack>
using namespace std;
bool okay (vector<int> &v, int ind) {
	int sum = 0;
	for (int i = 0; i < v.size(); i++) {
		if (i != ind) {
			sum += v[i];
		}
	}
	if (sum % 2 == 1) {
		return false;
	}
	bitset<5000> bs;
	bs[0] = true;
	for (int i = 0; i < v.size(); i++) {
		if (i != ind) {
			bs |= (bs << v[i]);
		}
	}
	return bs[sum/2];
}
vector<int> remove (vector<int> v, int ind) {
	vector<int> a;
	for (int i = 0; i < v.size(); i++) {
		if (i != ind) {
			a.push_back(v[i]);
		}
	}
	return a;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
    	cin >> v[i];
    }
    bitset<5000> bs;
    bs[0] = true;
    for (int i = 0; i < n - 1; i++) {
    	bs |= (bs >> v[i]) | (bs << v[i]);
    }
    vector<int> ans;
    for (int i = 0; i <= 5000; i++) {
    	if (!bs[i]) {
    		continue;
    	}
    	v.push_back(i);
    	bool fine = true;
    	for (int j = 0; j < v.size(); j++) {
    		if (!okay(v, j)) {
    			fine = false;
    			break;
    		}
    	}
    	if (fine) {
    		ans.push_back(i);
    	}
    	v.pop_back();
    }
    cout << ans.size() << endl;
    for (int i: ans) {
    	cout << i << ' ';
    }
    cout << endl;
}

Compilation message

bootfall.cpp: In function 'bool okay(std::vector<int>&, int)':
bootfall.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
bootfall.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
bootfall.cpp: In function 'std::vector<int> remove(std::vector<int>, int)':
bootfall.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |      for (int j = 0; j < v.size(); j++) {
      |                      ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Correct 25 ms 324 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 24 ms 212 KB Output is correct
15 Correct 19 ms 212 KB Output is correct
16 Correct 25 ms 320 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 19 ms 212 KB Output is correct
19 Correct 14 ms 320 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Correct 25 ms 324 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 24 ms 212 KB Output is correct
15 Correct 19 ms 212 KB Output is correct
16 Correct 25 ms 320 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 19 ms 212 KB Output is correct
19 Correct 14 ms 320 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Execution timed out 1072 ms 312 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Correct 25 ms 324 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 24 ms 212 KB Output is correct
15 Correct 19 ms 212 KB Output is correct
16 Correct 25 ms 320 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 19 ms 212 KB Output is correct
19 Correct 14 ms 320 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Execution timed out 1072 ms 312 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Correct 25 ms 324 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 24 ms 212 KB Output is correct
15 Correct 19 ms 212 KB Output is correct
16 Correct 25 ms 320 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 19 ms 212 KB Output is correct
19 Correct 14 ms 320 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Execution timed out 1072 ms 312 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 9 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 320 KB Output is correct
11 Correct 25 ms 324 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 24 ms 212 KB Output is correct
15 Correct 19 ms 212 KB Output is correct
16 Correct 25 ms 320 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 19 ms 212 KB Output is correct
19 Correct 14 ms 320 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Execution timed out 1072 ms 312 KB Time limit exceeded
22 Halted 0 ms 0 KB -