QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#195072 | #5475. Make a Loop | Mihailo_Jancevic | WA | 1ms | 3388kb | C++14 | 993b | 2023-10-01 00:36:45 | 2023-10-01 00:36:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, r[105], s;
vector<pair<int, int> > v;
map<int, int> dp;
int sgn(int n) {
if(n>=0) return 1;
return -1;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>r[i];
for(int i=1; i<=n; i++) s+=r[i];
if(n%2||s%2) {
cout<<"No";
exit(0);
}
dp[0]=1;
for(int i=1; i<=n; i++) {
for(auto p:dp) {
if(p.second<s/2)
v.push_back(make_pair((-sgn(p.first))*(abs(p.first)+r[i]), p.second));
//cout<<i<<' '<<p.first<<' '<<(-sgn(p.first))*(abs(p.first)+r[i])<<' '<<dp[(-sgn(p.first))*(abs(p.first)+r[i])]<<' '<<v.back().second<<'\n';
}
while(v.size()) {
dp[v.back().first]+=v.back().second;
v.pop_back();
}
//cout<<dp.size()<<'\n';
}
if(dp[s/2]>2) cout<<"Yes";
else cout<<"No";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3388kb
input:
4 1 1 1 1
output:
No
result:
wrong answer 1st lines differ - expected: 'Yes', found: 'No'