QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#379404#8566. Can We Still Qualify For Semifinals?ucup-team228#WA 1ms3868kbC++206.8kb2024-04-06 17:26:382024-04-06 17:26:41

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 17:26:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-04-06 17:26:38]
  • 提交

answer

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2") // doesn't work on Yandex
//#pragma GCC target("avx") // for old judges
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt") // fast bit operations

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>
#include <unordered_set>

using namespace std;
typedef long long ll;

string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
    return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
    bool first = true; string res = "{";
    for (const auto& i : a) {
        if (!first) res += ", ";
        first = false;
        res += to_string(i);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
    cerr << " " << to_string(a);
    debug_out(b...);
}

#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif

clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }

void Solve();

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
#ifdef LOCAL
    cerr << fixed << setprecision(3);
    cerr << endl << "Time spent: " << get_time() << endl;
#endif
    return 0;
}

// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush

// don't waste time on standings

// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT

const int N = 205;
const ll inf = 1e18;

struct Edge {
    int s, e;
    ll cap, flow;
};

vector<int> g[N];
vector<Edge> edges;
int dist[N], ptr[N];
queue<int> q;

void init() {
    for (int i = 0; i < N; i++) {
        g[i].clear();
        dist[i] = 0;
        ptr[i] = 0;
    }
    edges.clear();
    while (!q.empty()) q.pop();
}

void add_edge(int s, int e, ll cap) {
    Edge forw = {s, e, cap, 0};
    Edge back = {e, s, 0, 0};
    g[s].push_back(edges.size());
    edges.push_back(forw);
    g[e].push_back(edges.size());
    edges.push_back(back);
}

bool bfs(int src, int sink) {
    while (!q.empty()) q.pop();
    q.push(src);
    for (int i = 0; i < N; i++) {
        dist[i] = -1;
    }
    dist[src] = 0;
    while (!q.empty() && dist[sink] == -1) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < g[v].size(); i++) {
            int id = g[v][i];
            int u = edges[id].e;
            if (dist[u] == -1 && edges[id].flow < edges[id].cap) {
                q.push(u);
                dist[u] = dist[v] + 1;
            }
        }
    }
    return dist[sink] != -1;
}

ll dfs(int v, ll flow, int sink) {
    if (!flow) return 0;
    if (v == sink) return flow;
    while (ptr[v] < g[v].size()) {
        int id = g[v][ptr[v]];
        int u = edges[id].e;
        if (dist[u] != dist[v] + 1) {
            ptr[v]++;
            continue;
        }
        ll pushed = dfs(u, min(flow, edges[id].cap - edges[id].flow), sink);
        if (pushed) {
            edges[id].flow += pushed;
            edges[id^1].flow -= pushed;
            return pushed;
        }
        ptr[v]++;
    }
    return 0;
}

ll max_flow(int src, int sink) {
    ll flow = 0;
    while (1) {
        if (!bfs(src, sink)) break;
        for (int i = 0; i < N; i++) ptr[i] = 0;
        while (ll pushed = dfs(src, inf, sink)) {
            flow += pushed;
        }
    }
    return flow;
}

int bit(int mask, int i) {
    return (mask >> i) & 1;
}

const int n = 10;

vector<int> p;
vector<pair<int, int>> ms;
pair<int, int> cnt[n + 1];
pair<int, int> a[n + 1];

void Solve() {
    p.resize(10);
    iota(p.begin(), p.end(), 1);
    for (int r = 1; r <= 9; r++) {
        for (int i = 0; i <= 4; i++) {
            ms.push_back({p[i], p[9 - i]});
        }
        int last = p.back();
        for (int i = 9; i >= 2; i--) {
            p[i] = p[i - 1];
        }
        p[1] = last;
    }
    int T;
    cin >> T;
    while (T--) {
        for (int i = 1; i <= n; i++) {
            cnt[i] = {0, i};
        }
        int k;
        cin >> k;
        for (int i = 0; i < k; i++) {
            auto [x, y] = ms[i];
            char c;
            cin >> c;
            if (c == '1') {
                cnt[x].first++;
            }
            else {
                cnt[y].first++;
            }
        }
        vector<pair<int, int>> cur;
        for (int i = k; i < ms.size(); i++) {
            auto [x, y] = ms[i];
            if (x == 1 || y == 1) {
                cnt[1].first++;
            }
            else {
                cur.push_back(ms[i]);
            }
        }
        int india = cnt[1].first;
        bool ok = 0;
        for (int mask = 0; mask < (1 << (n + 1)); mask++) {
            if (bit(mask, 0) || bit(mask, 1)) continue;
            if (__builtin_popcount(mask) < 6) continue;
            bool bad = 0;
            for (int i = 1; i <= n; i++) {
                if (bit(mask, i) && cnt[i].first > india) {
                    bad = 1;
                    break;
                }
            }
            if (bad) continue;
            init();
            int src = 0;
            int sink = N - 1;
            int ptr = 11;
            for (auto [x, y] : cur) {
                if (!bit(mask, x) || !bit(mask, y)) continue;
                add_edge(src, ptr, 1);
                add_edge(ptr, x, 1);
                add_edge(ptr, y, 1);
                ptr++;
            }
            for (int i = 1; i <= 10; i++) {
                if (!bit(mask, i)) continue;
                add_edge(i, sink, india - cnt[i].first);
            }
            ll f = max_flow(src, sink);
            if (f == cur.size()) {
                ok = 1;
                break;
            }
        }
        if (ok) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3868kb

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: 3680kb

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: 1ms
memory: 3664kb

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: -100
Wrong Answer
time: 0ms
memory: 3756kb

input:

10
23
01100000010101000111010
38
01111001100011000101011110101001101001
27
010000000001001001110001001
26
01101001110011101101000110
8
00001000
22
0110100110001110110001
9
000100010
24
000000100101101010100100
6
011000
29
01101010100101000000000000100

output:

NO
NO
NO
NO
YES
NO
YES
NO
YES
NO

result:

wrong answer expected YES, found NO [1st token]