Submission #37412

#TimeUsernameProblemLanguageResultExecution timeMemory
37412HardNutBootfall (IZhO17_bootfall)C++14
Compilation error
0 ms0 KiB
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N = 1e5 + 5; typedef long long ll; int n, a[505], dp1[505][250005], dp2[505][250005], sum; vector<int> ans, vec;#include<iostream> #include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N = 1e5 + 5; typedef long long ll; int n, a[505], dp1[105][10005], dp2[105][10005], sum; vector<int> ans, vec; int dp[105][10005]; bool us[105][10005]; bool used[10005]; bool is(int s, int v) { if (us[v][s]) return dp[v][s]; us[v][s] = 1; for (int i = 0; i <= s; i++) { if ((dp1[v - 1][i] && dp2[v + 1][s - i]) || (dp2[v + 1][i] && dp1[v - 1][s - i])) { dp[v][s] = 1; return 1; } } dp[v][s] = 0; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { dp[i][0] = 1; cin >> a[i]; sum += a[i]; } if (sum % 2 == 1) { cout << 0; return 0; } bool u = 0; dp1[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= sum; j++) { if (dp1[i - 1][j]) { if (j + a[i] == sum / 2) u = 1; dp1[i][j + a[i]] = 1; dp1[i][j] = 1; dp[i][j + a[i]] = 1; } } } if (u == 0) { cout << 0; return 0; } dp2[n + 1][0] = 1; for (int i = n; i >= 1; i--) { for (int j = 0; j <= sum; j++) { if (dp2[i + 1][j]) { dp2[i][j + a[i]] = 1; dp2[i][j] = 1; dp[i][j + a[i]] = 1; } } } for (int i = 0; i <= sum; i++) { if (dp1[n - 1][i]) vec.push_back(i); } for (int i : vec) { int x = abs(i - (sum - a[n] - i)); bool u = 0; for (int j = 1; j <= n; j++) { if ((sum - a[j] + x) % 2) { u = 1; break; } if (!is((sum - a[j] + x) / 2, j)) { u = 1; break; } } if (!u) { if (!used[x]) { ans.push_back(x); used[x] = 1; } } } cout << ans.size() << "\n"; for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " "; } int dp[505][250005]; bool us[505][250005]; bool used[250005]; bool is(int s, int v) { if (us[v][s]) return dp[v][s]; us[v][s] = 1; for (int i = 0; i <= s; i++) { if ((dp1[v - 1][i] && dp2[v + 1][s - i]) || (dp2[v + 1][i] && dp1[v - 1][s - i])) { dp[v][s] = 1; return 1; } } dp[v][s] = 0; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { dp[i][0] = 1; cin >> a[i]; sum += a[i]; } if (sum % 2 == 1) { cout << 0; return 0; } bool u = 0; dp1[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= sum; j++) { if (dp1[i - 1][j]) { if (j + a[i] == sum / 2) u = 1; dp1[i][j + a[i]] = 1; dp1[i][j] = 1; dp[i][j + a[i]] = 1; } } } if (u == 0) { cout << 0; return 0; } dp2[n + 1][0] = 1; for (int i = n; i >= 1; i--) { for (int j = 0; j <= sum; j++) { if (dp2[i + 1][j]) { dp2[i][j + a[i]] = 1; dp2[i][j] = 1; dp[i][j + a[i]] = 1; } } } for (int i = 0; i <= sum; i++) { if (dp1[n - 1][i]) vec.push_back(i); } for (int i : vec) { int x = abs(i - (sum - a[n] - i)); bool u = 0; for (int j = 1; j <= n; j++) { if ((sum - a[j] + x) % 2) { u = 1; break; } if (!is((sum - a[j] + x) / 2, j)) { u = 1; break; } } if (!u) { if (!used[x]) { ans.push_back(x); used[x] = 1; } } } cout << ans.size() << "\n"; for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " "; }

Compilation message (stderr)

bootfall.cpp:12:22: error: stray '#' in program
 vector<int> ans, vec;#include<iostream>
                      ^
bootfall.cpp:12:23: error: 'include' does not name a type
 vector<int> ans, vec;#include<iostream>
                       ^
bootfall.cpp:19:11: error: redefinition of 'const int N'
 const int N = 1e5 + 5;
           ^
bootfall.cpp:7:11: note: 'const int N' previously defined here
 const int N = 1e5 + 5;
           ^
bootfall.cpp:23:5: error: redefinition of 'int n'
 int n, a[505], dp1[105][10005], dp2[105][10005], sum;
     ^
bootfall.cpp:11:5: note: 'int n' previously declared here
 int n, a[505], dp1[505][250005], dp2[505][250005], sum;
     ^
bootfall.cpp:23:13: error: redefinition of 'int a [505]'
 int n, a[505], dp1[105][10005], dp2[105][10005], sum;
             ^
bootfall.cpp:11:8: note: 'int a [505]' previously declared here
 int n, a[505], dp1[505][250005], dp2[505][250005], sum;
        ^
bootfall.cpp:23:30: error: conflicting declaration 'int dp1 [105][10005]'
 int n, a[505], dp1[105][10005], dp2[105][10005], sum;
                              ^
bootfall.cpp:11:16: note: previous declaration as 'int dp1 [505][250005]'
 int n, a[505], dp1[505][250005], dp2[505][250005], sum;
                ^
bootfall.cpp:23:47: error: conflicting declaration 'int dp2 [105][10005]'
 int n, a[505], dp1[105][10005], dp2[105][10005], sum;
                                               ^
bootfall.cpp:11:34: note: previous declaration as 'int dp2 [505][250005]'
 int n, a[505], dp1[505][250005], dp2[505][250005], sum;
                                  ^
bootfall.cpp:23:50: error: redefinition of 'int sum'
 int n, a[505], dp1[105][10005], dp2[105][10005], sum;
                                                  ^
bootfall.cpp:11:52: note: 'int sum' previously declared here
 int n, a[505], dp1[505][250005], dp2[505][250005], sum;
                                                    ^
bootfall.cpp:24:13: error: redefinition of 'std::vector<int> ans'
 vector<int> ans, vec;
             ^
bootfall.cpp:12:13: note: 'std::vector<int> ans' previously declared here
 vector<int> ans, vec;#include<iostream>
             ^
bootfall.cpp:24:18: error: redefinition of 'std::vector<int> vec'
 vector<int> ans, vec;
                  ^
bootfall.cpp:12:18: note: 'std::vector<int> vec' previously declared here
 vector<int> ans, vec;#include<iostream>
                  ^
bootfall.cpp:112:19: error: conflicting declaration 'int dp [505][250005]'
 int dp[505][250005];
                   ^
bootfall.cpp:25:5: note: previous declaration as 'int dp [105][10005]'
 int dp[105][10005];
     ^
bootfall.cpp:113:20: error: conflicting declaration 'bool us [505][250005]'
 bool us[505][250005];
                    ^
bootfall.cpp:26:6: note: previous declaration as 'bool us [105][10005]'
 bool us[105][10005];
      ^
bootfall.cpp:114:17: error: conflicting declaration 'bool used [250005]'
 bool used[250005];
                 ^
bootfall.cpp:27:6: note: previous declaration as 'bool used [10005]'
 bool used[10005];
      ^
bootfall.cpp: In function 'bool is(int, int)':
bootfall.cpp:116:6: error: redefinition of 'bool is(int, int)'
 bool is(int s, int v) {
      ^
bootfall.cpp:29:6: note: 'bool is(int, int)' previously defined here
 bool is(int s, int v) {
      ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:130:5: error: redefinition of 'int main()'
 int main() {
     ^
bootfall.cpp:43:5: note: 'int main()' previously defined here
 int main() {
     ^