QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627293 | #8566. Can We Still Qualify For Semifinals? | ucup-team2818# | WA | 2ms | 3636kb | C++14 | 3.4kb | 2024-10-10 15:27:48 | 2024-10-10 15:27:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 105;
const int maxm = 205;
const ll inf = 1e18;
int s, t;
struct edge
{
int v, next;
ll flow;
}e[2 * maxm];
int head[maxn], tot = -1;
inline void addedge(int u, int v, ll c)
{
e[++tot] = (edge){v, head[u], c};
head[u] = tot;
e[++tot] = (edge){u, head[v], 0};
head[v] = tot;
}
namespace Maxflow
{
int d[maxn], cur[maxn];
bool bfs()
{
memset(d, 0, sizeof(d));
memcpy(cur, head, sizeof(head));
queue<int> q;
q.push(s), d[s] = 1;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = e[i].next)
{
int v = e[i].v;
if (!d[v] && e[i].flow)
{
d[v] = d[u] + 1;
if (v == t) return true;
q.push(v);
}
}
}
return false;
}
ll dfs(int u, ll flow)
{
if (u == t || !flow) return flow;
ll rest = flow;
for (int i = cur[u]; ~i; i = e[i].next)
{
int v = e[i].v;
if (d[v] == d[u] + 1 && e[i].flow)
{
ll k = dfs(v, min(e[i].flow, rest));
if (!k) d[v] = 0;
e[i].flow -= k;
e[i ^ 1].flow += k;
rest -= k;
if (!rest) break;
}
cur[u] = i;
}
return flow - rest;
}
ll Dinic()
{
ll maxflow = 0;
while (bfs())
{
ll flow = 0;
while (flow = dfs(s, inf)) maxflow += flow;
}
return maxflow;
}
}
char str[55];
int a[15], b[15][15], c[15], typ[15], m, n;
bool ans;
bool calc()
{
s = t = 0; int k = 0;
memset(head, -1, sizeof(head)), tot = -1;
for (int i = 1; i <= 10; i++) a[i] = 0;
for (int i = 1; i <= n; i++)
{
int y = (i - 1) % 5 + 1, x = (i - y) / 5 + 1;
if (str[i] == '1') a[b[x][y]]++;
else a[b[x][11 - y]]++;
}
for (int i = n + 1; i <= 45; i++)
{
int y = (i - 1) % 5 + 1, x = (i - y) / 5 + 1;
int u = b[x][y], v = b[x][11 - y];
if (typ[u] > typ[v]) a[u]++;
else if (typ[u] < typ[v]) a[v]++;
else k++;
}
for (int i = n + 1; i <= 45; i++)
{
int y = (i - 1) % 5 + 1, x = (i - y) / 5 + 1;
int u = b[x][y], v = b[x][11 - y];
if (typ[u] == typ[v])
{
t++; addedge(s, t, 1);
addedge(t, k + u, 1), addedge(t, k + v, 1);
}
}
int nw = t + k + 1;
for (int i = t + 1; i <= t + k; i++) addedge(i, nw, a[1] - a[i - t]);
t = nw; return Maxflow::Dinic() == k;
}
void work()
{
ans = 0;
cin >> n >> str + 1;
for (int i = 1; i <= 10; i++) a[i] = 0;
typ[1] = 4;
for (int j = 2; j <= 10; j++)
for (int k = 2; k <= 10; k++)
for (int l = 2; l <= 10; l++)
{
if (j == k || j == l || k == l) continue;
typ[j] = 3, typ[k] = 2, typ[l] = 1;
ans |= calc();
typ[j] = typ[k] = typ[l] = 0;
if (ans) return cout << "Yes\n", void();
}
cout << (ans ? "YES\n" : "NO\n");
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 1; i <= 9; i++)
{
b[i][1] = 1;
for (int j = 2; j <= 10; j++) b[i][j] = (j - i + 17) % 9 + 2;
}
int T; cin >> T;
while (T--) work();
return 0;
}
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: 0ms
memory: 3616kb
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: -100
Wrong Answer
time: 2ms
memory: 3556kb
input:
10 37 0110000001010100011101001011100110001 39 000100111101101001100101101000000000100 35 00111000100111100101011010111100100 33 010000010001110010110001101110001 30 000100010100000010010110101010 31 0000101000011010101001010000000 44 00001000000111101011010110000101100011000100 42 01111011110001001...
output:
NO NO NO NO Yes NO Yes Yes Yes NO
result:
wrong answer expected NO, found YES [5th token]