#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
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3308 KB |
Output is correct |
2 |
Correct |
22 ms |
2420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3304 KB |
Output is correct |
2 |
Correct |
20 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2544 KB |
Output is correct |
2 |
Correct |
37 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2284 KB |
Output is correct |
2 |
Correct |
40 ms |
3672 KB |
Output is correct |
3 |
Correct |
44 ms |
3644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3316 KB |
Output is correct |
2 |
Correct |
22 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3684 KB |
Output is correct |
2 |
Correct |
24 ms |
2428 KB |
Output is correct |
3 |
Correct |
38 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2424 KB |
Output is correct |
2 |
Correct |
36 ms |
3284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
3816 KB |
Output is correct |
2 |
Correct |
20 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3260 KB |
Output is correct |
2 |
Correct |
21 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
3692 KB |
Output is correct |
2 |
Correct |
23 ms |
2420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3192 KB |
Output is correct |
2 |
Correct |
24 ms |
2420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3264 KB |
Output is correct |
2 |
Correct |
22 ms |
2288 KB |
Output is correct |