QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645606#6809. Code With No ForcesYnoiynoiWA 135ms65192kbC++173.5kb2024-10-16 19:09:502024-10-16 19:09:50

Judging History

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

  • [2024-10-16 19:09:50]
  • 评测
  • 测评结果:WA
  • 用时:135ms
  • 内存:65192kb
  • [2024-10-16 19:09:50]
  • 提交

answer

#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> PII;

const int N = 410, M = 8, NN = (1<<18) + 10, MM = 1<<6;

// 0 OK, 1 WA, 2 TL, 3 ML, 4 RE
vector<PII> e[NN]; // v, edge_id
int n, m;
struct Rec {
    int st, ti, mem;
    Rec() {}
    Rec(int st_, int ti_, int mem_): st(st_), ti(ti_), mem(mem_) {}
};
Rec rec[N][M], res[M];
char sts[5] = {'O', 'W', 'T', 'M', 'R'};
queue<int> q;
int pre[NN], d[NN], T, pid[NN];

int get(int x, int y, int z) { // vd, time, memory
    return x*MM*MM + y*MM + z;
}
Rec work(string s) {
    Rec ret;
    for(int i = 0; i < 5; i ++) {
        if(s[0] == sts[i]) ret.st = i;
    }
    int p1 = s.find(','), p2 = s.find('/');
    ret.ti = stoi(s.substr(p1+1, p2-p1-1));
    ret.mem = stoi(s.substr(p2+1));
    return ret;
}
int bfs() {
    memset(pre, -1, sizeof pre);
    memset(d, 0x3f, sizeof d);
    q.push(0);
    d[0] = 0;
    while(q.size()) {
        auto u = q.front(); q.pop();
        if(u == T) return d[T];
        for(auto [v, id]: e[u]) {
            if(v == u) continue;
            if(d[u]+1 < d[v]) {
                d[v] = d[u]+1;
                pre[v] = u;
                pid[v] = id;
                q.push(v);
            }
        }
    }
    return d[T];
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) {
        for(int j = 0; j < m; j ++) {
            string s; cin >> s;
            rec[i][j] = work(s);
            if(!res[j].st) {
                res[j].st = rec[i][j].st;
                res[j].ti = max(res[j].ti, rec[i][j].ti);
                res[j].mem = max(res[j].mem, rec[i][j].mem);
            }
        }
    }
    for(int St = 0; St < (1<<m); St ++) {
        for(int Ti = 0; Ti < (1<<m); Ti ++) {
            for(int Mem = 0; Mem < (1<<m); Mem ++) {
                int id = get(St, Ti, Mem);
                int mask = St & Ti & Mem;
                for(int i = 1; i <= n; i ++) {
                    bool ok = true;
                    for(int j = 0; j < m; j ++) {
                        if((~mask>>j & 1) && (!res[j].st || (~St>>j & 1))) { // 考虑限制
                            // 不是 ac 且不同
                            // ti超出限制
                            // mem超出限制
                            if(rec[i][j].st && res[j].st != rec[i][j].st ||
                                rec[i][j].ti > res[j].ti ||
                                rec[i][j].mem > res[j].mem) {
                                ok = false;
                                break;
                            }
                        }
                    }
                    if(ok) {
                        int nst = St, nti = Ti, nmem = Mem;
                        for(int j = 0; j < m; j ++) {
                            if(rec[i][j].st == res[j].st) nst |= 1<<j;
                            if(rec[i][j].ti == res[j].ti) nti |= 1<<j;
                            if(rec[i][j].mem == res[j].mem) nmem |= 1<<j;
                        }
                        int nid = get(nst, nti, nmem);
                        e[id].eb(nid, i);
                    }
                }
            }
        }
    }
    T = get((1<<m)-1, (1<<m)-1, (1<<m)-1);
    cout << bfs() << '\n';
    int t = T;
    vector<int> ans;
    while(pre[t] != -1) {
        ans.pb(pid[t]);
        t = pre[t];
    }
    for(int i = ans.size()-1; i >= 0; i --) {
        cout << ans[i] << " \n"[i==0];
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 12688kb

input:

2 3
OK,1/1 OK,2/1 OK,2/2
WA,1/1 OK,1/1 TL,1000/1

output:

2
1 2

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 11860kb

input:

3 3
OK,1/1 OK,2/1 OK,1/2
OK,3/3 OK,1/2 OK,114/514
WA,999/999 TL,3000/2 ML,999/1024

output:

1
3

result:

ok ok

Test #3:

score: 0
Accepted
time: 3ms
memory: 12324kb

input:

5 3
OK,0/0 OK,0/0 OK,0/0
WA,1/0 RE,0/0 OK,0/0
WA,0/0 WA,0/0 WA,0/0
OK,1/0 RE,0/0 OK,0/0
WA,2/2 RE,2/2 WA,2/2

output:

2
2 3

result:

ok ok

Test #4:

score: 0
Accepted
time: 135ms
memory: 65192kb

input:

21 6
OK,0/34 OK,15/1 OK,0/1 OK,0/4 OK,0/1 OK,0/36
OK,0/34 OK,0/1 OK,15/1 OK,15/4 OK,0/1 OK,0/36
OK,0/34 OK,15/1 OK,0/1 OK,0/4 OK,15/1 OK,0/36
OK,0/34 OK,0/1 OK,0/1 OK,0/4 OK,15/1 OK,0/36
OK,0/34 OK,0/1 OK,15/1 OK,0/4 OK,0/1 OK,0/36
OK,0/34 OK,0/1 OK,0/1 OK,0/4 OK,0/1 OK,0/36
OK,0/34 OK,0/1 OK,0/1 OK...

output:

7
9 10 12 13 15 17 20

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 11868kb

input:

1 1
TL,10000/10000

output:

1
1

result:

ok ok

Test #6:

score: 0
Accepted
time: 2ms
memory: 12096kb

input:

1 1
OK,0/0

output:

1
1

result:

ok ok

Test #7:

score: 0
Accepted
time: 0ms
memory: 12096kb

input:

398 1
TL,10000/3499
OK,99/4999
WA,3899/2299
OK,7899/399
RE,2399/4399
OK,9499/4199
WA,7699/799
OK,7299/2099
OK,1999/9399
OK,2899/6999
OK,5899/4999
OK,4199/8499
OK,6399/4399
RE,2699/4399
RE,9699/9799
TL,10000/1399
ML,9499/10000
OK,5599/4499
RE,3699/5699
OK,1799/4099
ML,1399/10000
ML,2199/10000
OK,2599...

output:

1
1

result:

ok ok

Test #8:

score: 0
Accepted
time: 3ms
memory: 12664kb

input:

398 2
ML,0/10000 OK,1666/1666
ML,3333/10000 OK,3333/0
OK,0/8332 WA,3333/0
TL,10000/3333 OK,1666/3333
OK,3333/1666 OK,4999/4999
ML,8332/10000 RE,6666/3333
OK,8332/8332 OK,8332/0
OK,4999/1666 OK,3333/0
OK,1666/3333 OK,3333/1666
OK,4999/8332 OK,6666/3333
OK,4999/6666 OK,8332/4999
RE,3333/1666 OK,3333/6...

output:

2
1 3

result:

ok ok

Test #9:

score: 0
Accepted
time: 4ms
memory: 12248kb

input:

398 3
OK,2199/7699 OK,6599/2399 WA,8199/1499
ML,2299/10000 OK,6099/4199 ML,599/10000
ML,699/10000 WA,4299/1599 OK,6099/8399
TL,10000/3199 TL,10000/5599 OK,9699/2999
RE,9799/599 WA,4999/6199 OK,9599/9899
OK,899/8899 OK,4499/7499 OK,3199/5899
TL,10000/3599 WA,8299/8299 RE,6199/6999
RE,5599/4299 OK,709...

output:

3
1 2 3

result:

ok ok

Test #10:

score: -100
Wrong Answer
time: 15ms
memory: 17072kb

input:

398 4
OK,0/6666 OK,1666/1666 WA,3333/0 ML,8332/10000
OK,3333/8332 OK,0/4999 ML,3333/10000 OK,0/6666
OK,6666/3333 TL,10000/3333 OK,0/0 OK,1666/1666
OK,3333/3333 WA,4999/3333 WA,4999/0 OK,4999/0
OK,1666/0 OK,0/6666 ML,4999/10000 OK,3333/8332
OK,3333/0 ML,3333/10000 OK,8332/6666 OK,0/3333
OK,0/4999 ML,...

output:

3
1 3 77

result:

wrong answer memory mismatched on file 2