Submission #253695

#TimeUsernameProblemLanguageResultExecution timeMemory
253695MrRobot_28Slagalica (COCI19_slagalica2)C++17
70 / 70
44 ms3816 KiB
#include<bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; bool type1 = 0, type2 = 0; int end; int cnt1 = 0, cnt4 = 0; vector <int> types; vector <pair<int, int> > mass1, mass2; for(int i = 0; i < n; i++) { int x, a; cin >> x >> a; if(x == 5 || x == 6) { types.push_back(a); } else if(x == 7 || x == 8) { end = a; } if(x == 5) { type1 = 1; } if(x == 7) { type2 = 1; } if(x == 1) { cnt1++; } if(x == 4) { cnt4++; } if(x == 1 || x == 2) { mass1.push_back({a, x}); } else if(x == 3 || x == 4) { mass2.push_back({a, x}); } } if(type1 && type2 && cnt1 + 1 != cnt4) { cout << -1; return 0; } if(!type1 && !type2 && cnt4 + 1 != cnt1) { cout << -1; return 0; } if(type1 ^ type2) { if(cnt1 != cnt4) { cout << -1; return 0; } if(cnt1 == 0) { if(type1 && (int)mass1.size() || type2 && (int)mass2.size()) { cout << -1; return 0; } } } sort(mass1.begin(), mass1.end()); sort(mass2.begin(), mass2.end()); int it1 = 0, it2 = 0; bool flag = !type1; int it3 = 0; while(!((it1 == mass1.size() && flag) || (it2 == mass2.size() && !flag))) { if(flag) { if(mass1[it1].second == 1) { flag = 0; it3 = types.size() - 1; } types.push_back(mass1[it1].first); it1++; } else { if(mass2[it2].second == 4) { flag = 1; it3 = types.size() - 1; } types.push_back(mass2[it2].first); it2++; } } for(int i = 0; i < it3 + 1; i++) { cout << types[i] << " "; } while(it1 != mass1.size()) { cout << mass1[it1].first << " "; it1++; } while(it2 != mass2.size()) { cout << mass2[it2].first << " "; it2++; } for(int i = it3 + 1; i < types.size(); i++) { cout << types[i] << " "; } cout << end; return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:72:13: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if(type1 && (int)mass1.size() || type2 && (int)mass2.size())
       ~~~~~~^~~~~~~~~~~~~~~~~~~~
slagalica.cpp:84:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(!((it1 == mass1.size() && flag) || (it2 == mass2.size() && !flag)))
           ~~~~^~~~~~~~~~~~~~~
slagalica.cpp:84:48: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(!((it1 == mass1.size() && flag) || (it2 == mass2.size() && !flag)))
                                            ~~~~^~~~~~~~~~~~~~~
slagalica.cpp:111:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(it1 != mass1.size())
        ~~~~^~~~~~~~~~~~~~~
slagalica.cpp:116:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(it2 != mass2.size())
        ~~~~^~~~~~~~~~~~~~~
slagalica.cpp:121:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = it3 + 1; i < types.size(); i++)
                       ~~^~~~~~~~~~~~~~
slagalica.cpp:125:7: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << end;
  ~~~~~^~~~~~
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...