#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
const int maxn = 1e6 + 5;
const string BADTRI = "neispravna triangulacija";
const string NOTPAT = "neispravno bojenje";
const string GOOD = "tocno";
struct iv {
int l,r,c;
void read() {
cin>>l>>r>>c;
--l; --r;
}
};
int n;
string s;
vector<iv> w;
int dist(int l, int r) {
return (r-l+n)%n;
}
string solve() {
w.clear();
cin>>n;
cin>>s;
w.resize(n-3);
for (int i=0; i<n-3; i++) {
w[i].read();
}
vector<pair<int,int>> nxt(n);
for (int i=0; i<n; i++) {
nxt[i].first = (i+1)%n;
nxt[i].second = int(s[i]-'0');
}
vector<pair<pair<int,int>,int>> diags;
for (auto p: w) {
diags.push_back({{p.l,p.r},p.c});
diags.push_back({{p.r,p.l},p.c});
}
sort(diags.begin(), diags.end(), [&](pair<pair<int,int>,int> a, pair<pair<int,int>,int> b) {
return dist(a.first.first,a.first.second) < dist(b.first.first,b.first.second);
});
bool coloring = true;
for (int i=0; i<n-2; i++) {
auto cur = diags[i];
//cout<<cur.first.first+1<<" "<<cur.first.second+1<<endl;
int a = cur.first.first;
int b = nxt[a].first;
int c = cur.first.second;
if (nxt[b].first != c) {
return BADTRI;
}
vector<int> colors = {cur.second, nxt[a].second, nxt[b].second};
if ((int)set<int>(colors.begin(), colors.end()).size() < 3) {
coloring = false;
return NOTPAT;
}
nxt[a] = {c, cur.second};
}
if (!coloring) {
return NOTPAT;
}
return GOOD;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t;
cin>>t;
cout<<solve()<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
10856 KB |
Output is correct |
2 |
Correct |
175 ms |
11004 KB |
Output is correct |
3 |
Correct |
171 ms |
10984 KB |
Output is correct |
4 |
Correct |
145 ms |
11132 KB |
Output is correct |
5 |
Correct |
145 ms |
10984 KB |
Output is correct |
6 |
Correct |
223 ms |
10984 KB |
Output is correct |
7 |
Correct |
189 ms |
10984 KB |
Output is correct |
8 |
Correct |
167 ms |
11120 KB |
Output is correct |
9 |
Correct |
164 ms |
10980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
10856 KB |
Output is correct |
2 |
Correct |
174 ms |
10984 KB |
Output is correct |
3 |
Correct |
138 ms |
10984 KB |
Output is correct |
4 |
Correct |
135 ms |
10984 KB |
Output is correct |
5 |
Correct |
151 ms |
10984 KB |
Output is correct |
6 |
Correct |
192 ms |
10984 KB |
Output is correct |
7 |
Correct |
201 ms |
10984 KB |
Output is correct |
8 |
Correct |
166 ms |
10984 KB |
Output is correct |
9 |
Correct |
166 ms |
10984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
172 ms |
10856 KB |
Output is correct |
16 |
Correct |
175 ms |
11004 KB |
Output is correct |
17 |
Correct |
171 ms |
10984 KB |
Output is correct |
18 |
Correct |
145 ms |
11132 KB |
Output is correct |
19 |
Correct |
145 ms |
10984 KB |
Output is correct |
20 |
Correct |
223 ms |
10984 KB |
Output is correct |
21 |
Correct |
189 ms |
10984 KB |
Output is correct |
22 |
Correct |
167 ms |
11120 KB |
Output is correct |
23 |
Correct |
164 ms |
10980 KB |
Output is correct |
24 |
Correct |
174 ms |
10856 KB |
Output is correct |
25 |
Correct |
174 ms |
10984 KB |
Output is correct |
26 |
Correct |
138 ms |
10984 KB |
Output is correct |
27 |
Correct |
135 ms |
10984 KB |
Output is correct |
28 |
Correct |
151 ms |
10984 KB |
Output is correct |
29 |
Correct |
192 ms |
10984 KB |
Output is correct |
30 |
Correct |
201 ms |
10984 KB |
Output is correct |
31 |
Correct |
166 ms |
10984 KB |
Output is correct |
32 |
Correct |
166 ms |
10984 KB |
Output is correct |
33 |
Correct |
168 ms |
10980 KB |
Output is correct |
34 |
Correct |
172 ms |
11132 KB |
Output is correct |
35 |
Correct |
164 ms |
10984 KB |
Output is correct |
36 |
Correct |
144 ms |
10984 KB |
Output is correct |
37 |
Correct |
134 ms |
11112 KB |
Output is correct |
38 |
Correct |
157 ms |
11112 KB |
Output is correct |
39 |
Correct |
138 ms |
10984 KB |
Output is correct |
40 |
Correct |
193 ms |
10984 KB |
Output is correct |
41 |
Correct |
195 ms |
10984 KB |
Output is correct |
42 |
Correct |
164 ms |
10980 KB |
Output is correct |
43 |
Correct |
165 ms |
10984 KB |
Output is correct |