#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
struct bracket{
int pos; int other; bool open; int colour;
};
bool comp(bracket a, bracket b){
if(a.pos != b.pos) return a.pos < b.pos;
if(a.open && !b.open) return false;
if(!a.open && b.open) return true;
if(a.open){
return a.other > b.other;
}
else{
return a.other > b.other;
}
}
void notTriangle(){
cout << "neispravna triangulacija";
exit(0);
}
int main(){
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
int ST; cin >> ST;
int n; cin >> n;
string S; cin >> S;
vector<bracket> B;
for(int i = 0;i < n;i++){
int l = i+1;
int r = i+2;
if(r == n+1) r = 1;
if(l > r) swap(l,r);
int c = S[i] - '0';
B.push_back({l,r,true,c});
B.push_back({r,l,false,c});
}
for(int i = 0;i < n-3;i++){
int l, r, c; cin >> l >> r >> c;
if(l > r) swap(l,r);
B.push_back({l,r,true,c});
B.push_back({r,l,false,c});
}
sort(B.begin(),B.end(),comp);
stack<ii> s;
for(bracket b : B){
//cout << b.pos << " " << b.other << " " << b.open << " " << b.colour << endl;
if(b.open) s.push(ii(b.pos,b.other));
else{
ii t = s.top();
if(t.first != b.other && t.second != b.pos){
notTriangle();
}
else s.pop();
}
}
cout << "tocno";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
17120 KB |
Output is correct |
2 |
Correct |
205 ms |
17116 KB |
Output is correct |
3 |
Correct |
204 ms |
17124 KB |
Output is correct |
4 |
Correct |
198 ms |
17120 KB |
Output is correct |
5 |
Correct |
207 ms |
17120 KB |
Output is correct |
6 |
Correct |
206 ms |
17132 KB |
Output is correct |
7 |
Correct |
201 ms |
17148 KB |
Output is correct |
8 |
Correct |
193 ms |
17140 KB |
Output is correct |
9 |
Correct |
192 ms |
17140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
17252 KB |
Output is correct |
2 |
Correct |
197 ms |
17120 KB |
Output is correct |
3 |
Incorrect |
202 ms |
17120 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |