제출 #36067

#제출 시각아이디문제언어결과실행 시간메모리
36067UncleGrandpa925Bootfall (IZhO17_bootfall)C++14
65 / 100
1000 ms4824 KiB
/*input 4 1 3 1 5 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define N 505 #define bit(x,y) ((x>>y)&1LL) #define na(x) (#x) << ":" << x ostream& operator << (ostream &os, vector<int>&x) { for (int i = 0; i < x.size(); i++) os << x[i] << sp; return os; } ostream& operator << (ostream &os, pair<int, int> x) { cout << x.fi << sp << x.se << sp; return os; } ostream& operator << (ostream &os, vector<pair<int, int> >&x) { for (int i = 0; i < x.size(); i++) os << x[i] << endl; return os; } const int mod = 1e9 + 7; int n; int a[N]; int f[250005]; int sum = 0; int mark[250005]; vector<int> order; bool used[N]; signed main() { scanf("%d", &n); f[0] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); int x = a[i]; for (int i = sum; i >= 0; i--) { f[i + x] += f[i]; if (f[i + x] >= mod) f[i + x] -= mod; } sum += x; } if (sum % 2 || f[sum / 2] == 0) { printf("0\n"); return 0; } int cnt = 0; for (int i = 1; i <= n; i++) { if (used[a[i]]) continue; used[a[i]] = true; cnt++; int x = a[i]; for (int i = 0; i <= sum; i++) { f[i + x] += (mod - f[i]); if (f[i + x] >= mod) f[i + x] -= mod; } sum -= x; int sta = 1; if (sum % 2 == 0) sta++; for (int j = sta; j <= sum; j += 2) { if (f[((sum + j) >> 1) - j]) mark[j]++; } for (int i = sum; i >= 0; i--) { f[i + x] += f[i]; if (f[i + x] >= mod) f[i + x] -= mod; } sum += x; } for (int i = 1; i <= sum; i++) if (mark[i] == cnt) order.push_back(i); printf("%d\n", order.size()); for (int i = 0; i < order.size(); i++) { printf("%d ", order[i]); } }

컴파일 시 표준 에러 (stderr) 메시지

bootfall.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
bootfall.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
bootfall.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<int, int> >&)':
bootfall.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:75:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", order.size());
                             ^
bootfall.cpp:76:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < order.size(); i++) {
                    ^
bootfall.cpp:38:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
bootfall.cpp:41:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...