QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233661 | #7636. Fair Elections | ucup-team296 | TL | 0ms | 3888kb | C++14 | 2.2kb | 2023-10-31 20:58:15 | 2023-10-31 20:58:15 |
Judging History
answer
#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
vector<vector<int>> d;
bool interesting(int i, int j) {
if (d[i + 1][j] != d[i][j]) return true;
if (d[i][j + 1] != d[i][j]) return true;
return false;
}
void print() {
for (auto &a : d) {
for (auto x : a) {
cout << x << " ";
}
cout << "\n";
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(3));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
d.assign(n + 2, vector<int>(n + 2, -1));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
int k = n - i - j;
if (k >= 0 && k <= n) {
if (i >= j && i >= k) {
d[i][j] = 0;
} else if (j >= k) {
d[i][j] = 1;
} else {
d[i][j] = 2;
}
}
}
}
vector<pair<int, int>> fr;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (d[i][j] == -1) continue;
if (interesting(i, j)) fr.push_back({i, j});
}
}
// print();
for (int t = n - 1; t >= 0; t--) {
sort(fr.begin(), fr.end());
fr.erase(unique(fr.begin(), fr.end()), fr.end());
vector<pair<int, int>> nfr;
for (auto [i, j] : fr) {
int r = -1;
for (int x : a[t]) {
if (d[i][j + 1] == x || d[i + 1][j] == x || d[i][j] == x) {
r = x;
break;
}
}
if (r != d[i][j]) {
d[i][j] = r;
if (i > 0 && interesting(i - 1, j)) nfr.push_back({i - 1, j});
if (j > 0 && interesting(i, j - 1)) nfr.push_back({i, j - 1});
}
if (interesting(i, j)) nfr.push_back({i, j});
}
fr = nfr;
// print();
}
cout << d[0][0] + 1 << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
3 3 2 1 1 2 3 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
5 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
5 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
20 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
20 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2 1 2 3 3 1 2 1 3 2 3 2 1 1 3 2 2 1 3 3 1 2 2 3 1 2 1 3 2 3 1 3 1 2 3 1 2 2 1 3 3 1 2 1 2 3
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 1 2 3 2 3 1 2 1 3 2 1 3 1 3 2 3 1 2 2 3 1 1 3 2 3 1 2 1 2 3 1 2 3 3 2 1 3 1 2 1 2 3 3 2 1 1 2 3 2 3 1 3 1 2 3 2 1 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
20 3 1 2 3 2 1 1 2 3 1 3 2 1 3 2 2 3 1 1 3 2 2 3 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 2 3 1 2 3 1 1 2 3 2 1 3 2 1 3
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
20 2 1 3 2 1 3 3 1 2 3 2 1 2 1 3 1 2 3 2 3 1 3 1 2 3 1 2 2 3 1 3 2 1 1 3 2 2 1 3 2 1 3 1 2 3 2 3 1 2 3 1 3 2 1 2 1 3 1 3 2
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: -100
Time Limit Exceeded
input:
10000 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2 1 2 3 3 1 2 1 3 2 3 2 1 1 3 2 2 1 3 3 1 2 2 3 1 2 1 3 2 3 1 3 1 2 3 1 2 2 1 3 3 1 2 1 2 3 1 2 3 2 3 1 2 1 3 2 1 3 1 3 2 3 1 2 2 3 1 1 3 2 3 1 2 ...