이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int a[1001];
bool reachable(int p, int r, int sum) {
if(sum==0) return 1;
else if(sum<0) return 0;
if(p==r) return 0;
return max(reachable(p+1, r, sum-a[p]), reachable(p+1, r, sum));
}
void solve() {
int n;
cin >> n;
int pref[n+1];
pref[0]=0;
for(int i=1; i<=n; i++) {
cin >> a[i];
pref[i]=pref[i-1]+a[i];
}
vector<int>ans;
for(int i=2; i<=n; i++) {
bool pos=1;
for(int j=1; j<=n-i+1; j++) {
int x=pref[j+i-1]-pref[j-1];
if(x%2) {
pos=0;
break;
}
x/=2;
if(!reachable(j, j+i, x)) pos=0;
}
if(pos) ans.push_back(i);
}
cout << ans.size() << " ";
for(int i=0; i<ans.size(); i++) cout << ans[i] << " ";
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0; i<ans.size(); i++) cout << ans[i] << " ";
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |