QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233628 | #7636. Fair Elections | ucup-team296 | WA | 1ms | 3852kb | C++14 | 2.2kb | 2023-10-31 20:33:35 | 2023-10-31 20:33:35 |
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 (interesting(i, j)) nfr.push_back({i, j});
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});
}
}
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: 1ms
memory: 3684kb
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: 3652kb
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: -100
Wrong Answer
time: 0ms
memory: 3852kb
input:
5 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'