QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379335 | #8566. Can We Still Qualify For Semifinals? | ucup-team3113# | AC ✓ | 10ms | 3868kb | C++20 | 3.4kb | 2024-04-06 17:10:38 | 2024-04-06 17:10:39 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
const int inf = 1e18;
void p(auto A){
for(auto e : A)cout << e << ' ';
cout << '\n';
}
typedef int64_t ll;
typedef vector<int> vi;
struct PushRelabel {
struct Edge {
int dest, back;
ll f, c;
};
vector<vector<Edge>> g;
vector<ll> ec;
vector<Edge*> cur;
vector<vi> hs; vi H;
PushRelabel(int n) : g(n), ec(n), cur(n), hs(2*n), H(n) {}
void addEdge(int s, int t, ll cap, ll rcap=0) {
if (s == t) return;
g[s].push_back({t, sz(g[t]), 0, cap});
g[t].push_back({s, sz(g[s])-1, 0, rcap});
}
void addFlow(Edge& e, ll f) {
Edge &back = g[e.dest][e.back];
if (!ec[e.dest] && f) hs[H[e.dest]].push_back(e.dest);
e.f += f; e.c -= f; ec[e.dest] += f;
back.f -= f; back.c += f; ec[back.dest] -= f;
}
ll calc(int s, int t) {
int v = sz(g); H[s] = v; ec[t] = 1;
vi co(2*v); co[0] = v-1;
rep(i,0,v) cur[i] = g[i].data();
for (Edge& e : g[s]) addFlow(e, e.c);
for (int hi = 0;;) {
while (hs[hi].empty()) if (!hi--) return -ec[s];
int u = hs[hi].back(); hs[hi].pop_back();
while (ec[u] > 0) // discharge u
if (cur[u] == g[u].data() + sz(g[u])) {
H[u] = 1e9;
for (Edge& e : g[u]) if (e.c && H[u] > H[e.dest]+1)
H[u] = H[e.dest]+1, cur[u] = &e;
if (++co[H[u]], !--co[hi] && hi < v)
rep(i,0,v) if (hi < H[i] && H[i] < v)
--co[H[i]], H[i] = v + 1;
hi = H[u];
} else if (cur[u]->c && H[u] == H[cur[u]->dest]+1)
addFlow(*cur[u], min(ec[u], cur[u]->c));
else ++cur[u];
}
}
bool leftOfMinCut(int a) { return H[a] >= sz(g); }
};
void solve(){
vector<pii> games;
vector<int> teams;
for(int i = 2; i<= 10; i++)teams.pb(i);
for(int i = 0; i< 9; i++){
games.pb({1, teams.back()});
for(int j = 0; j< 4; j++)games.pb({teams[j], teams[teams.size()-j-2]});
rotate(teams.rbegin(), teams.rbegin()+1, teams.rend());
}
//for(auto&[x, y] : games)if(x > y)swap(x, y);
//for(auto[x, y]:games)cout << x << ' ' << y << endl;
int k; cin >> k;
string A; cin >> A;
vector<int>points(11);
for(int i = 0; i< k; i++){
if(A[i]=='1')points[games[i].X]++;
else points[games[i].Y]++;
}
for(int i = k; i< 45; i++){
if(games[i].X==1||games[i].Y==1)points[1]++;
}
int mx = points[1];
for(int i = 2; i<= 10; i++){
for(int j = i+1; j<= 10; j++){
for(int l = j+1; l<= 10; l++){
PushRelabel F(60);
for(int g = 1; g<= 45; g++)F.addEdge(0, g, 1);
for(int id = 1; id <= k; id++){
if(A[id-1]=='1')F.addEdge(id, 45+games[id-1].X, 1);
else F.addEdge(id, 45+games[id-1].Y, 1);
}
for(int id = k+1; id <= 45; id++){
F.addEdge(id, 45+games[id-1].X, 1);
F.addEdge(id, 45+games[id-1].Y, 1);
}
for(int id = 1; id<= 10; id++){
if(id==1||id==i||id==j||id==l)F.addEdge(45+id, 56, 100);
else F.addEdge(45+id, 56, mx);
}
if(F.calc(0, 56) == 45){
cout << "YES\n";
return;
}
}
}
}
cout << "NO\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while(t--)solve();
}
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
input:
3 3 111 25 1000010101111111111010100 35 01111011110111101111011110111101111
output:
YES YES NO
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
10 16 0110000001010100 17 01111000110110101 15 001100010101111 16 0010101010011100 19 0000000100010110100 16 0011101010011100 18 011110010001100000 18 000110101001100011 20 01100010000100100100 15 001000111001101
output:
YES YES YES YES YES YES YES YES YES YES
result:
ok 10 token(s): yes count is 10, no count is 0
Test #3:
score: 0
Accepted
time: 6ms
memory: 3588kb
input:
10 37 0110000001010100011101001011100110001 39 000100111101101001100101101000000000100 35 00111000100111100101011010111100100 33 010000010001110010110001101110001 30 000100010100000010010110101010 31 0000101000011010101001010000000 44 00001000000111101011010110000101100011000100 42 01111011110001001...
output:
NO NO NO NO NO NO NO NO NO NO
result:
ok 10 token(s): yes count is 0, no count is 10
Test #4:
score: 0
Accepted
time: 4ms
memory: 3660kb
input:
10 23 01100000010101000111010 38 01111001100011000101011110101001101001 27 010000000001001001110001001 26 01101001110011101101000110 8 00001000 22 0110100110001110110001 9 000100010 24 000000100101101010100100 6 011000 29 01101010100101000000000000100
output:
YES NO NO NO YES YES YES YES YES NO
result:
ok 10 token(s): yes count is 6, no count is 4
Test #5:
score: 0
Accepted
time: 5ms
memory: 3824kb
input:
10 30 011000000101010001110100101110 29 01001010010011101110010110010 28 0110000000001000101101001001 23 01101001110011101101000 23 01000001000111001011000 24 011110001000010001010000 23 01001011010101001000011 30 000110011001010010000000000010 24 000110111001110011000011 28 000110001000011011110110...
output:
NO NO NO YES YES YES YES NO YES NO
result:
ok 10 token(s): yes count is 5, no count is 5
Test #6:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
10 21 011000000101010001110 21 000110110101001010010 22 0111101101001100101101 24 000000001000101011000101 21 011010011100111011010 20 00110000010001101010 21 010010111100010000100 24 010100000100011010110010 23 00001010000110101010010 25 0000000000001000001101110
output:
YES YES YES YES YES YES YES YES YES YES
result:
ok 10 token(s): yes count is 10, no count is 0
Test #7:
score: 0
Accepted
time: 10ms
memory: 3636kb
input:
10 26 01100000010101000111010010 26 01101010010100100111011100 26 00110010110100000000010010 27 011100010101110010110101101 30 010100011000001000110101001100 30 011110001000010001010000001001 28 0101100101000010100001101010 26 00101000000000000100000110 28 0110101101010000111000110001 27 00011011110...
output:
NO NO NO NO NO NO NO NO NO NO
result:
ok 10 token(s): yes count is 0, no count is 10
Test #8:
score: 0
Accepted
time: 9ms
memory: 3640kb
input:
10 25 0010100010011010111001111 26 01001010100010101010001010 26 01111001110000100111011110 26 10001000100110101110011110 26 10101010100110101110011110 27 110100010101010011010111001 27 101010101001101011100111101 31 1000010001010100110001011011110 37 1000101111000100110000011000000100101 40 1000101...
output:
NO NO NO NO NO NO NO NO NO NO
result:
ok 10 token(s): yes count is 0, no count is 10
Test #9:
score: 0
Accepted
time: 6ms
memory: 3868kb
input:
10 26 00001010000000000000000000 26 00000010000000000000000000 26 01101010100010101011011110 26 00011011110111101111011110 27 001100110101011001110111101 27 000110111101111011110111101 28 0110001001000010011101111011 29 01000000010001101000011110111 29 01000000010000101101011110111 30 01000011110111...
output:
YES YES YES YES YES YES YES YES YES NO
result:
ok 10 token(s): yes count is 9, no count is 1
Test #10:
score: 0
Accepted
time: 4ms
memory: 3804kb
input:
10 1 0 2 00 10 0001101110 14 00101010000011 20 00000010010100101010 25 0000000101000100100001111 35 01110011010000101010000010010000100 40 0000100110001110101100001001000110000001 44 01011010110010101110011000010001010011100011 45 010010001001010011110111101011011000000100001
output:
YES YES YES YES YES YES NO NO NO NO
result:
ok 10 token(s): yes count is 6, no count is 4
Extra Test:
score: 0
Extra Test Passed