답안 #566280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566280 2022-05-22T08:11:48 Z 1zaid1 Bootfall (IZhO17_bootfall) C++17
0 / 100
126 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define int long long

#pragma GCC diagnostic ignored "-Wunused-result"
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(15);
    if (name.size()) {
    	freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

const int M = 5e2+5, MOD = 1e6+7;
bool can[M][M];
int a[M];


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    // setIO("citystate");

    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    can[0][0] = 1;
    vector<int> ans;
    for (int k = 1; k <= 1000; k++) {
        int ok = 1;
        for (int r = 1; r <= n; r++) {
            if ((sum-a[r]+k)%2) {
                ok = false;
                break;
            }

            sum += k;
            sum -= a[r];
            swap(a[r], k);
            for (int x = 1; x <= sum/2; x++) {
                for (int i = 1; i <= n; i++) {
                    can[i][x] = can[i-1][x];
                    if (a[i] <= x) can[i][x] |= can[i-1][x-a[i]];
                }
            }

            if (!can[n][sum/2]) ok = false;
            for (int x = 1; x <= sum/2; x++) for (int i = 1; i <= n; i++) can[i][x] = 0;
            swap(a[r], k);
            sum += a[r];
            sum -= k;
        }

        for (int x = 1; x <= sum/2; x++) {
            for (int i = 1; i <= n; i++) {
                can[i][x] = can[i-1][x];
                if (a[i] <= x) can[i][x] |= can[i-1][x-a[i]];
            }
        }

        if (!can[n][sum/2]) ok = false;
        for (int x = 1; x <= sum/2; x++) for (int i = 1; i <= n; i++) can[i][x] = 0;

        if (ok) ans.push_back(k);
    }

    cout << ans.size() << endl;
    for (int i:ans) cout << i << ' '; cout << endl;

    return 0;
}

/*
4
1 3 1 5
*/

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:76:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   76 |     for (int i:ans) cout << i << ' '; cout << endl;
      |     ^~~
bootfall.cpp:76:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   76 |     for (int i:ans) cout << i << ' '; cout << endl;
      |                                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 12 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 15 ms 340 KB Output is correct
5 Incorrect 126 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -