QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507950 | #7636. Fair Elections | pandapythoner | WA | 0ms | 3788kb | C++23 | 2.6kb | 2024-08-07 01:04:45 | 2024-08-07 01:04:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())
const ll inf = 1e18;
mt19937 rnd(234);
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n;
cin >> n;
vector<vector<int>> p(n);
rep(i, n) {
p[i].resize(3);
rep(j, 3) {
cin >> p[i][j];
--p[i][j];
}
}
vector<vector<int>> pos(n);
rep(i, n) {
pos[i].resize(3);
rep(j, 3) {
pos[i][p[i][j]] = j;
}
}
vector<vector<pair<int, int>>> dp(n + 1);
for (int x = 0; x <= n; x += 1) {
if (n - 2 * x > 0) {
dp[x].push_back(make_pair(0, 2));
}
if (max(0, n - 2 * x) <= x) {
dp[x].push_back(make_pair(max(0, n - 2 * x), 0));
}
int val = max({ x + 1, (n - x + 1) / 2 });
if (val <= n - x) {
dp[x].push_back(make_pair(val, 1));
}
dp[x].push_back(make_pair(10 * n + 10000, -1));
}
for (int cnt = n - 1; cnt >= 0; cnt -= 1) {
vector<vector<pair<int, int>>> ndp(cnt + 1);
for (int x = 0; x <= cnt; x += 1) {
auto& a = dp[x + 1];
auto& b = dp[x];
auto c = dp[x];
for (auto& f : c) f.first -= 1;
int i = 0, j = 0, k = 0;
// int last_min = -1;
int cur_pos = 0;
while (i < len(a) - 1 or j < len(b) - 1 or k < len(c) - 1) {
cur_pos = min({ a[i].first, b[j].first, c[k].first });
int mn = max({ a[i].second, b[j].second, c[k].second });
if (j < len(b) - 1 and pos[cnt][mn] > pos[cnt][b[j].second]) {
mn = b[j].second;
}
if (k < len(c) - 1 and pos[cnt][mn] > pos[cnt][c[k].second]) {
mn = c[k].second;
}
ndp[x].push_back(make_pair(cur_pos, mn));
if (a[i].first == cur_pos) ++i;
if (b[j].first == cur_pos) ++j;
if (c[k].first == cur_pos) ++k;
}
ndp[x].push_back(make_pair(10 * n + 10000, -1));
}
dp.swap(ndp);
}
assert(!dp.empty() and !dp[0].empty());
int result = -1;
for (auto [cur_pos, cur_val] : dp[0]) {
if (cur_pos <= 0) {
result = cur_val;
}
}
cout << result + 1 << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
3 3 2 1 1 2 3 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3600kb
input:
5 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'