답안 #236758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236758 2020-06-03T08:36:25 Z VEGAnn Vođe (COCI17_vode) C++14
72 / 120
3000 ms 524292 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define ft first
#define sd second
using namespace std;
typedef long long ll;
const int N = 5010;
const int oo = int(2e9);
const ll OO = 1e18;
const int md = int(1e9) + 7;
set<short> st[N];
set<short>::iterator ite;
short mem[N][N], fen[N][N], net[N], tp[N], n, m, k;

void upd(int id, int ps){
    for (; ps < m; ps = (ps | (ps + 1)))
        fen[id][ps]++;
}

int sum(int id, int ps){
    int res = 0;
    for (; ps >= 0; ps = (ps & (ps + 1)) - 1)
        res += fen[id][ps];
    return res;
}

int get(int ps, int vl){
    if (mem[ps][vl] > 0) return mem[ps][vl] - 1;

    if (vl == m - 1) {
        mem[ps][vl] = 1;
        return 0;
    }

    int res = 0;

    int rt = min(vl + k, m - 1);

    while (1){
        ite = st[net[ps]].upper_bound(rt);

        if (ite == st[net[ps]].begin()) break;

        int nw = *prev(ite);

        if (nw <= vl) break;

        mem[net[ps]][nw] = get(net[ps], nw) + 1;

        if (mem[net[ps]][nw] == 2)
            upd(net[ps], nw);

        st[net[ps]].erase(nw);
    }

    if (tp[net[ps]] == tp[ps]){
        if (sum(net[ps], rt) - sum(net[ps], vl) > 0)
            res = 1;
    } else {
        if (sum(net[ps], rt) - sum(net[ps], vl) < rt - vl)
            res = 1;
    }

    mem[ps][vl] = res + 1;

    return res;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m >> k;

    k = min(m, k);

    for (int i = 0; i < n; i++) {
        cin >> tp[i];
        net[i] = (i + 1) % n;

        for (int j = 1; j <= m; j++)
            st[i].insert(j);
    }

    for (int i = 0; i < n; i++){
        int ans = 0;

        ans = get(i, 0);

        cout << (tp[i] ^ ans ^ 1) << " ";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 6 ms 1536 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6016 KB Output is correct
2 Correct 10 ms 2432 KB Output is correct
3 Correct 28 ms 5760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5632 KB Output is correct
2 Correct 23 ms 5248 KB Output is correct
3 Correct 29 ms 5888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 9080 KB Output is correct
2 Correct 56 ms 10744 KB Output is correct
3 Correct 56 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 15096 KB Output is correct
2 Correct 88 ms 13820 KB Output is correct
3 Correct 67 ms 12280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 13560 KB Output is correct
2 Correct 92 ms 14076 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2389 ms 165088 KB Output is correct
2 Correct 2428 ms 184312 KB Output is correct
3 Runtime error 1193 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3110 ms 360936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1220 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1208 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -