Submission #721081

# Submission time Handle Problem Language Result Execution time Memory
721081 2023-04-10T09:52:14 Z Magikarp4000 Alternating Current (BOI18_alternating) C++17
0 / 100
68 ms 5824 KB
#include <bits/stdc++.h>
using namespace std;
#define INF int(1e9+7)
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define ln '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
const ll LLINF = 1e18+1;

struct Wire {
    int l,r,idx;
};

const int MAXN = 1e5+1;
int n,m;
PII p[MAXN], q[MAXN];
bool res[MAXN], z[MAXN];
vector<Wire> pro,noob;
int pn,nn;
int w[MAXN];

bool cmp(const Wire& x, const Wire& y) {
    return x.l < y.l;
}

bool check(int k) {
    vector<PII> a,b;
    vector<int> dir(m,0);
    FOR(i,0,m) res[i] = 0;
    FOR(i,0,pn) {
        if ((i+k)%2 == 0) {
            a.PB(q[pro[(i+k)%pn].idx]);
            dir[pro[i].idx] = 0;
        }
        else {
            b.PB(q[pro[(i+k)%pn].idx]);
            dir[pro[i].idx] = 1;
            res[pro[i].idx] = 1;
        }
    }
    FOR(i,0,nn) {
        if (dir[w[noob[i].idx]] == 0) {
            b.PB(q[noob[i].idx]);
            res[noob[i].idx] = 1;
        }
        else a.PB(q[noob[i].idx]);
    }
    sort(ALL(a));
    sort(ALL(b));
    // FORX(u,a) cout << u.F << ' ';
    // cout << ln;
    // FORX(u,b) cout << u.F << ' ';
    // cout << ln;
    // cout << ln;
    int pos = a[0].S, idx = 0;
    while (idx < a.size() && pos < a[0].F+n-1) {
        if (a[idx].F > pos+1) return 0;
        pos = a[idx].S;
        idx++;
    }
    if (pos < a[0].F+n-1) return 0;
    pos = b[0].S, idx = 0;
    while (idx < b.size() && pos < b[0].F+n-1) {
        if (b[idx].F > pos+1) return 0;
        pos = pos,b[idx].S;
        idx++;
    }
    if (pos < b[0].F+n-1) return 0;
    return 1;
}

signed main() {
    cin >> n >> m;
    FOR(i,0,m) cin >> p[i].F >> p[i].S;
    FOR(i,0,m) {
        q[i].F = p[i].F;
        q[i].S = p[i].S < p[i].F ? p[i].S+n : p[i].S;
    }
    FOR(i,0,m) {
        if (z[i]) continue;
        FOR(j,0,m) {
            if (i == j) continue;
            if ((q[i].F <= q[j].F && q[i].S >= q[j].S) || 
            ((p[i].S%n) == p[i].F-1) || 
            (p[j].S >= p[j].F && q[i].F <= p[j].F+n && q[i].S >= p[j].S+n)) {
                z[j] = 1;
                w[j] = i;
            }
        }
    }
    FOR(i,0,m) {
        if (!z[i]) pro.PB({q[i].F,q[i].S,i});
        else noob.PB({q[i].F,q[i].S,i});
    }
    sort(ALL(pro),cmp);
    sort(ALL(noob),cmp);
    // FORX(u,pro) cout << u.idx << ' ';
    // cout << ln;
    // FORX(u,noob) cout << u.idx << ' ';
    // cout << ln;
    pn = pro.size(), nn = noob.size();
    FOR(i,0,pn) {
        // FOR(j,0,pn) {
        //     if ((j+i)%2 == 0) cout << (i+j)%pn;
        // }
        // cout << ln;
        // FOR(j,0,pn) {
        //     if ((j+i)%2 == 1) cout << (i+j)%pn;
        // }
        // cout << ln << ln;
        if (check(i)) {
            FOR(j,0,m) cout << res[j];
            return 0;
        }
    }
    cout << "impossible";
}

Compilation message

alternating.cpp: In function 'bool check(int)':
alternating.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     while (idx < a.size() && pos < a[0].F+n-1) {
      |            ~~~~^~~~~~~~~~
alternating.cpp:70:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     while (idx < b.size() && pos < b[0].F+n-1) {
      |            ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 5824 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 42 ms 3008 KB Output is correct
4 Incorrect 33 ms 2948 KB 'impossible' claimed, but there is a solution
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -