QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507956 | #7636. Fair Elections | pandapythoner | RE | 0ms | 3832kb | C++23 | 3.0kb | 2024-08-07 01:11:37 | 2024-08-07 01:11:37 |
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;
int vala = -1, valb = -1, valc = -1;
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 });
if (a[i].first == cur_pos) {
vala = a[i].second;
++i;
}
if (b[j].first == cur_pos) {
valb = b[j].second;
++j;
}
if (c[k].first == cur_pos) {
valc = c[k].second;
++k;
}
int mn = vala;
if (mn == -1 or (valb != -1 and pos[cnt][mn] > pos[cnt][valb])) {
mn = valb;
}
if (mn == -1 or (valc != -1 and pos[cnt][mn] > pos[cnt][valc])) {
mn = valc;
}
if (mn != last_min) {
ndp[x].push_back(make_pair(cur_pos, mn));
last_min = mn;
}
}
ndp[x].push_back(make_pair(10 * n + 10000, -1));
assert(len(ndp[x]) <= 4);
}
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: 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: 3620kb
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: 3832kb
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: 3492kb
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: -100
Runtime Error
input:
5 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1