Task: | Missing Coin Sum |
Sender: | Nallue |
Submission time: | 2024-11-23 16:06:14 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | TIME LIMIT EXCEEDED | -- | details |
#5 | ACCEPTED | 0.17 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; bool subsetExists(const vector<int>& vec, int final, int sum, map<pair<int,int>,bool>& m){ if(sum == 0) return true; if(sum < 0) return false; if(final == 0) return false; auto f = m.find(make_pair(final-1,sum)); bool first = (f != m.end() and f->second); auto s = m.find(make_pair(final-1,sum-vec[final-1])); bool second = (s != m.end() and s->second); bool temp = first or second or subsetExists(vec, final-1, sum, m) or subsetExists(vec, final-1, sum-vec[final-1], m); m[make_pair(final,sum)] = temp; return temp; } int main(){ int n; cin >> n; vector<int> vec(n); for(int i=0;i<n; i++) cin >> vec[i]; map<pair<int,int>,bool> m; int idx=0; while(subsetExists(vec, n, idx, m)) idx += 1; cout<< idx << endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
4 2 1 4 3 |
correct output |
---|
11 |
user output |
---|
11 |
Test 2
Verdict: ACCEPTED
input |
---|
4 2 2 2 2 |
correct output |
---|
1 |
user output |
---|
1 |
Test 3
Verdict: ACCEPTED
input |
---|
6 1 9 9 1 2 2 |
correct output |
---|
7 |
user output |
---|
7 |
Test 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 38 62 12 96 82 18 48 47 22 3 6... |
correct output |
---|
10114269 |
user output |
---|
(empty) |
Test 5
Verdict: ACCEPTED
input |
---|
200000 321076699 332784673 745614086 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 136292223 60613622 935902310... |
correct output |
---|
5069547 |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
60 1 2 4 8 16 32 64 128 256 512 1... |
correct output |
---|
31073741824 |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 2 4 8 16 32 64 128 256 512 1... |
correct output |
---|
53672058814464 |
user output |
---|
(empty) |
Test 9
Verdict: ACCEPTED
input |
---|
10 1 1 1 1 1 1 1 1 2 7 |
correct output |
---|
18 |
user output |
---|
18 |