QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420474#2653. Swapping Placesnick832WA 2ms3880kbC++202.1kb2024-05-24 19:05:592024-05-24 19:05:59

Judging History

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

  • [2024-05-24 19:05:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3880kb
  • [2024-05-24 19:05:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long //instead of int main, use signed main
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pii;

signed main(){
    IOS;

    int S, fs, N; cin >> S >> fs >> N;
    
    vector<string> ns(S); for(auto& i : ns) cin >> i;
    sort(ns.begin(), ns.end());
    map<string, int> inv;
    for(int i = 0; i < S; i++) inv[ns[i]] = i;

    map<pii, int> f;
    for(int i = 0; i < fs; i++){
        string u, v; cin >> u >> v;
        int p = inv[u], q = inv[v];
        f[{p, q}] = f[{q, p}] = 1;
    }

    vector<string> ans(N);
    for(int i = 0; i < N; i++) cin >> ans[i];

    vector<int> rank(N);
    vector<string> tmp(N);
    vector<vi> cnt(N + 1, vi(S));
    function<void(int, int)> solve = [&](int L, int R){
        if(L == R) return;
        int mid = (L + R) / 2;
        solve(L, mid);
        solve(mid + 1, R);

        for(int j = 0; j < S; j++) cnt[L][j] = 0;
        for(int i = L; i <= mid; i++){
            cnt[i + 1] = cnt[i];
            cnt[i + 1][inv[ans[i]]]++;
        }
        rank[mid] = L;
        for(int i = mid + 1; i <= R; i++){
            int l = rank[i - 1], r = mid;
            while(l <= r){
                int cur = (l + r) / 2;
                bool chk = true;
                for(int j = 0; j < S; j++){
                    if(cnt[mid + 1][j] - cnt[cur][j] == 0) continue;
                    if(f.find({inv[ans[i]], j}) != f.end() && j >= inv[ans[i]]) continue;
                    chk = false;
                }
                if(chk) r = cur - 1;
                else l = cur + 1;
            }
            rank[i] = l;
        }

        for(int i = L, j = mid + 1, k = L; i <= mid; i++){
            while(j <= R && rank[j] <= i) tmp[k++] = ans[j++];
            tmp[k++] = ans[i];

            if(i == mid) while(j <= R) tmp[k++] = ans[j++];
        }
        for(int i = L; i <= R; i++) ans[i] = tmp[i];
    };
    solve(0, N - 1);
    for(auto& i : ans) cout << i << ' ';
    cout << endl;
}

详细

Test #1:

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

input:

3 2 6
ANTILOPE
CAT
ANT
CAT ANTILOPE
ANTILOPE ANT
ANT CAT CAT ANTILOPE CAT ANT

output:

ANT ANTILOPE CAT CAT CAT ANT 

result:

ok single line: 'ANT ANTILOPE CAT CAT CAT ANT '

Test #2:

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

input:

2 0 10
CAT
ANT
CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT

output:

CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT 

result:

ok single line: 'CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT '

Test #3:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

3 1 100
ANACONDA
CAT
DOG
CAT DOG
CAT CAT ANACONDA DOG DOG ANACONDA DOG ANACONDA DOG DOG DOG ANACONDA DOG ANACONDA DOG CAT DOG ANACONDA DOG DOG CAT DOG ANACONDA CAT CAT DOG DOG CAT ANACONDA DOG ANACONDA CAT CAT CAT CAT ANACONDA ANACONDA CAT CAT CAT ANACONDA ANACONDA CAT ANACONDA ANACONDA DOG CAT ANAC...

output:

CAT CAT ANACONDA DOG DOG ANACONDA DOG ANACONDA DOG DOG DOG ANACONDA DOG ANACONDA CAT DOG DOG ANACONDA CAT DOG DOG DOG ANACONDA CAT CAT CAT DOG DOG ANACONDA DOG ANACONDA CAT CAT CAT CAT ANACONDA ANACONDA CAT CAT CAT ANACONDA ANACONDA CAT ANACONDA ANACONDA CAT DOG ANACONDA CAT CAT DOG ANACONDA CAT ANA...

result:

ok single line: 'CAT CAT ANACONDA DOG DOG ANACO...G DOG DOG DOG ANACONDA CAT DOG '

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3804kb

input:

8 24 1000
BEE
CAT
ZEBRA
DOG
ELEPHANT
ANT
LION
TIGER
BEE CAT
DOG ZEBRA
ELEPHANT TIGER
ANT CAT
ANT LION
CAT ELEPHANT
CAT LION
DOG ELEPHANT
ANT TIGER
BEE LION
ANT BEE
CAT TIGER
CAT DOG
ANT DOG
CAT ZEBRA
LION TIGER
BEE TIGER
BEE DOG
ELEPHANT ZEBRA
ANT ZEBRA
DOG TIGER
ANT ELEPHANT
TIGER ZEBRA
LION ZEBRA
...

output:

ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ...

result:

wrong answer 1st lines differ - expected: 'ANT ANT ANT ANT ANT ANT ANT AN...A ZEBRA ZEBRA ZEBRA ZEBRA ZEBRA', found: 'ANT ANT ANT ANT ANT ANT ANT AN... ZEBRA ZEBRA ZEBRA ZEBRA ZEBRA '