QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420473 | #2653. Swapping Places | nick832 | WA | 0ms | 3580kb | C++20 | 2.1kb | 2024-05-24 19:04:59 | 2024-05-24 19:05:01 |
Judging History
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;){
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
input:
3 2 6 ANTILOPE CAT ANT CAT ANTILOPE ANTILOPE ANT ANT CAT CAT ANTILOPE CAT ANT
output:
ANT CAT ANTILOPE ANT
result:
wrong answer 1st lines differ - expected: 'ANT ANTILOPE CAT CAT CAT ANT', found: 'ANT CAT ANTILOPE ANT '