QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770613 | #2992. 劈配 | propane | 30 | 3ms | 13980kb | C++20 | 4.1kb | 2024-11-21 22:40:41 | 2024-11-21 22:40:42 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
using LL = long long;
const int maxn = 405, maxm = 6005;
struct Flow{
int n, m, idx;
int h[maxn], f[maxm], e[maxm];
int d[maxn], pre[maxn], ne[maxn];
vector<pair<int *, int> > ops;
Flow() : n(0) {}
void init(int _n, int _m){
n = _n, m = _m;
for(int i = 0; i <= n + m; i++){
h[i] = -1;
}
idx = 0;
ops.clear();
}
void add(int a, int b, int c){
ops.push_back({&h[a], h[a]});
ops.push_back({&h[b], h[b]});
e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;
e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;
}
void undo(int ver){
while(ops.size() > ver){
auto [x, y] = ops.back();
ops.pop_back();
*x = y;
idx -= 1;
}
}
bool bfs(int st, bool type){
for(int i = 0; i <= n + m; i++) d[i] = -1;
queue<int> q;
d[st] = 0;
q.push(st);
while(!q.empty()){
int t = q.front();
q.pop();
for(int i = h[t]; ~i; i = ne[i]){
int j = e[i];
if (f[i] and d[j] == -1){
d[j] = d[t] + 1;
pre[j] = i;
q.push(j);
}
}
}
if (d[0] != -1){
if (type){
int t = 0;
while(t != st){
f[pre[t]] -= 1;
f[pre[t] ^ 1] += 1;
t = e[pre[t] ^ 1];
}
}
return true;
}
return false;
}
}f[201];
vector<int> pos[205][205];
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T, C;
cin >> T >> C;
while(T--){
int n, m;
cin >> n >> m;
f[0].init(n, m);
for(int i = 1; i <= m; i++){
int x;
cin >> x;
f[0].add(n + i, 0, x);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
pos[i][j].clear();
}
}
vector<int> ans1(n + 1, m + 1);
vector<int> ans2(n + 1);
for(int i = 1; i <= n; i++){
f[i] = f[i - 1];
for(int j = 1; j <= m; j++){
int x;
cin >> x;
pos[i][x].push_back(j);
}
for(int j = 1; j <= m; j++){
if (pos[i][j].empty()) continue;
int bk = f[i].ops.size();
for(auto x : pos[i][j]){
f[i].add(i, n + x, 1);
}
if (f[i].bfs(i, true)){
ans1[i] = j;
break;
}
f[i].undo(bk);
}
}
for(int i = 1; i <= n; i++){
int x;
cin >> x;
if (ans1[i] <= x){
ans2[i] = 0;
continue;
}
auto check = [&](int mid){
int bk = f[mid - 1].ops.size();
for(int j = 1; j <= x; j++){
for(auto y : pos[i][j]){
f[mid - 1].add(i, n + y, 1);
}
}
bool ret = f[mid - 1].bfs(i, false);
f[mid - 1].undo(bk);
return ret;
};
int l = 0, r = i;
while(l < r){
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
ans2[i] = i - r;
}
for(int i = 1; i <= n; i++){
cout << ans1[i] << " \n"[i == n];
}
for(int i = 1; i <= n; i++){
cout << ans2[i] << " \n"[i == n];
}
}
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 3ms
memory: 13896kb
input:
5 1 10 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 0 1 2 3 4 5 6 7 8 9 1 1 2 2 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3 1 1 4 4 4 4 4 1 0 0 1 2 3 4 6 1 1 1 2 2 4 4 4 4 4 0 0 0 4 2 6 2 8 4 5 2 2 2 4 4 4 4 4 4 4 1 2 3 4 2 3 7 8 9 7 3 3 1 1 3 2 1 4 1 2 0 0 5 6 0 1
result:
ok 10 lines
Test #4:
score: 0
Runtime Error
input:
5 1 100 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3...
output:
result:
Test #5:
score: 0
Runtime Error
input:
5 1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...
output:
result:
Test #6:
score: 0
Runtime Error
input:
5 1 200 200 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
result:
Test #7:
score: 0
Runtime Error
input:
5 1 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 ...
output:
result:
Test #8:
score: 0
Runtime Error
input:
5 10 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
output:
result:
Test #9:
score: 0
Runtime Error
input:
5 10 200 200 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
result:
Test #10:
score: 0
Runtime Error
input:
5 10 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200...