QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515716#4374. What Really Happened on Mars?karunaWA 1ms3632kbC++203.2kb2024-08-11 21:52:322024-08-11 21:52:33

Judging History

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

  • [2024-08-11 21:52:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2024-08-11 21:52:32]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int SZ = 30;

int n, r, occ[SZ], rnk[SZ], pr[SZ], st[SZ], ans[SZ], has[SZ], sp[SZ];
vector<pii> C[SZ];
vector<int> G[SZ];

int vis[SZ], cur[SZ];
int dfs(int v) {
    vis[v] = true;
    int ret = cur[v];
    for (int x : G[v]) {
        if (!vis[x]) {
            ret = max(ret, dfs(x));
        }
    }
    return ret;
}
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> r;
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> pr[i];
        int sz;
        cin >> sz;
        for (int j = 0; j < sz; j++) {
            string S;
            cin >> S;
            char c = S[0];
            int num = stoi(S.substr(1));
            if (c == 'C') {
				while (num--) C[i].push_back({0, 1});
			}
            if (c == 'L') C[i].push_back({1, num});
            if (c == 'U') C[i].push_back({2, num});
        }
    }
    for (int i = 1; i <= n; i++) {
        for (auto [t, x] : C[i]) if (t == 1) rnk[x] = max(rnk[x], pr[i]);
    }
    int t = 0;
    while (true) {
        fill(cur, cur + n + 1, 0);
        int yes[n + 1]{};

		bool flag = false;
        for (int i = 1; i <= n; i++) {
			if (st[i] <= t && sp[i] < C[i].size()) yes[i] = true;
			if (sp[i] < C[i].size()) flag = true;
        }
		if (!flag) break;

        for (int i = 1; i <= n; i++) G[i].clear();
        for (int i = 1; i <= n; i++) if (yes[i]) {
            cur[i] = pr[i];
            if (C[i][sp[i]].ff == 1 && occ[C[i][sp[i]].ss]) {
                G[occ[C[i][sp[i]].ss]].push_back(i);
                yes[i] = false;
            }
        }

        for (int i = 1; i <= n; i++) {
            if (yes[i]) cur[i] = max(cur[i], dfs(i));
            fill(vis + 1, vis + 1 + n, 0);
        }

        int k = -1, elt;

        for (int i = 1; i <= r; i++) if (occ[i] && (k == -1 || rnk[i] > rnk[k])) {
            k = i;
            elt = occ[i];
        }

        if (k != -1) {
            int block[n + 1]{};
            int maxv = 0;
            for (int i = 1; i <= n; i++) if (yes[i] && C[i][sp[i]].ff == 1) {
                if (cur[i] <= rnk[k] && i != elt) {
                    block[i] = true;
                    maxv = max(maxv, cur[i]);
                }
            }

            for (int i = 1; i <= n; i++) if (yes[i] && !block[i]) {
                if (has[i]) cur[i] = max(cur[i], maxv);
            }
            for (int i = 1; i <= n; i++) if (block[i]) yes[i] = false;
        }

        int at = -1;
        for (int i = 1; i <= n; i++) if (yes[i] && (at == -1 || cur[at] < cur[i])) at = i;

		if (at == -1) {
			++t;
			continue;
		}
        auto [type, x] = C[at][sp[at]++];

        if (type == 0) {
            ans[at] = t + x;
            t += x;
        }
        else if (type == 1) {
            occ[x] = at;
            has[at]++;
        }
        else if (type == 2) {
            occ[x] = 0;
            has[at]--;
        }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

3 1
50 2 5 C1 L1 C1 U1 C1
1 1 5 C1 L1 C100 U1 C1
70 3 1 C1

output:

106
107
71

result:

ok 3 lines

Test #2:

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

input:

3 3
5 3 5 C1 L1 C1 U1 C1
3 2 9 C1 L2 C1 L3 C1 U3 C1 U2 C1
1 1 9 C1 L3 C3 L2 C1 U2 C1 U3 C1

output:

8
15
16

result:

ok 3 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3632kb

input:

19 8
7 7 23 L8 C5 C1 C1 L1 U1 L5 L3 U3 U5 U8 C1 C4 L3 L1 C2 U1 U3 L3 C2 C4 U3 C2
19 14 6 L7 L3 L4 U4 U3 U7
6 5 3 L1 U1 C5
35 2 18 L2 L5 L7 U7 C3 C3 C3 U5 U2 L4 L1 C2 C2 C5 U1 U4 L3 U3
45 6 3 C3 L6 U6
32 3 10 C4 C1 C3 L1 L6 L8 C2 U8 U6 U1
17 17 50 L4 L6 C4 L8 U8 U6 U4 L1 L5 L2 L8 L4 L3 L7 L6 U6 U7 U3...

output:

329
0
337
379
332
361
106
307
0
251
285
209
419
59
136
201
351
114
57

result:

wrong answer 2nd lines differ - expected: '136', found: '0'