# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
711649 | 2023-03-17T10:38:29 Z | guagua0407 | Slagalica (COCI19_slagalica2) | C++17 | 28 ms | 2124 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() {_ int n; cin>>n; vector<int> num[9]; vector<int> adj[9]; vector<int> sz(9,0); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; num[a].push_back(b); sz[a]++; } for(int i=1;i<9;i++){ sort(num[i].rbegin(),num[i].rend()); } adj[1].push_back(3); adj[1].push_back(4); adj[1].push_back(8); adj[3].push_back(3); adj[3].push_back(4); adj[3].push_back(8); adj[5].push_back(3); adj[5].push_back(4); adj[5].push_back(8); adj[2].push_back(1); adj[2].push_back(2); adj[2].push_back(7); adj[4].push_back(1); adj[4].push_back(2); adj[4].push_back(7); adj[6].push_back(1); adj[6].push_back(2); adj[6].push_back(7); int cur=(sz[5]>0?5:6); vector<int> ans; ans.push_back(num[cur].back()); num[cur].pop_back(); sz[cur]--; for(int i=0;i<n-2;i++){ //cout<<cur<<'\n'; int mn=1e9+1; int tt; for(auto v:adj[cur]){ //cout<<v<<' '<<sz[v]<<'\n'; if(sz[v]==0) continue; sz[v]--; bool tf=false; for(auto u:adj[v]){ if(i!=n-3 and (u==7 or u==8)) continue; if(sz[u]>0){ tf=true; break; } } sz[v]++; if(tf){ if(num[v].back()<mn){ mn=num[v].back(); tt=v; } } } if(mn==1e9+1){ cout<<-1; return 0; } sz[tt]--; ans.push_back(num[tt].back()); num[tt].pop_back(); cur=tt; } int target=(sz[7]>0?7:8); bool tf=false; for(auto v:adj[cur]){ if(v==target){ tf=true; break; } } if(!tf){ cout<<-1; return 0; } ans.push_back(num[target].back()); for(auto v:ans){ cout<<v<<' '; } return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 2124 KB | Output is correct |
2 | Correct | 28 ms | 1260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 1848 KB | Output is correct |
2 | Correct | 24 ms | 1396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 968 KB | Output is correct |
2 | Incorrect | 24 ms | 1232 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 1048 KB | Output is correct |
2 | Correct | 27 ms | 1784 KB | Output is correct |
3 | Incorrect | 21 ms | 1368 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 996 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 1860 KB | Output is correct |
2 | Correct | 21 ms | 1020 KB | Output is correct |
3 | Incorrect | 22 ms | 1252 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 1424 KB | Output is correct |
2 | Incorrect | 25 ms | 1460 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 1452 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 1376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 1340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 1396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 1360 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |