QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#249113 | #5466. Permutation Compression | joelgun14 | WA | 0ms | 7916kb | C++14 | 2.3kb | 2023-11-12 00:57:37 | 2023-11-12 00:57:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAXN = 2e5 + 5;
const ll MAX = 1e18;
ll t, n, m, k;
ll arra[MAXN], arrb[MAXN], l[MAXN];
bool ada[MAXN];
bool urutan() {
ll idb = 0;
for (int i = 1; i <= m; ++i) {
for (int j = idb+1; j <= n; ++j) {
if (arra[j] == arrb[i]) {
idb = j;
if (j == n && i < m) {
return false;
}
break ;
} else {
if (j == n) {
return false;
}
}
}
}
return true;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> t;
while(t--) {
bool ans = true;
cin >> n >> m >> k;
// Input
for (int i = 1; i <= n; ++i) {
cin >> arra[i];
ada[arra[i]] = false;
}
for (int i = 1; i <= m; ++i) {
cin >> arrb[i];
ada[arrb[i]] = true;
}
for (int i = 1; i <= k; ++i) {
cin >> l[i];
}
// General Check
if (n-m > k) {
ans = false;
}
if (!urutan()) {
ans = false;
}
if(ans && n != m) {
vector<pll> hapus; vector<ll> vecl;
hapus.clear(); vecl.clear();
for (int i = 1; i <= k; ++i) {
vecl.push_back(l[i]);
}
for (int i = 1; i <= n; ++i) {
if (!ada[arra[i]]) {
hapus.push_back({arra[i], i});
arra[i] = -1;
}
}
sort(hapus.begin(), hapus.end());
sort(vecl.begin(), vecl.end(), greater<ll>());
arra[0] = MAX;
arra[n+1] = MAX;
for (int w = 0; w < hapus.size(); ++w) {
pll now = hapus[w];
// {Value, Index}
arra[now.second] = now.first;
ll berapa = 1;
// Cari L
for (int i = now.second-1; i >= 1; --i) {
if (arra[i] == -1) {
continue ;
}
if(arra[i] > now.first) {
break ;
}
berapa++;
}
// Cari R
for (int i = now.second+1; i <= n; ++i) {
if (arra[i] == -1) {
continue ;
}
if(arra[i] > now.first) {
break ;
}
berapa++;
}
bool flag = false;
// Make yang mana
for (int i = 0; i < vecl.size(); ++i) {
if (vecl[i] > berapa) {
continue ;
}
vecl.erase(vecl.begin()+i);
sort(vecl.begin(), vecl.end(), greater<ll>());
flag = true;
break ;
}
if(!flag) {ans = false; break ;}
}
}
if (ans) {
cout << "ya\n";
} else {
cout << "tidak\n";
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7916kb
input:
3 5 2 3 5 1 3 2 4 5 2 1 2 4 5 5 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 2 2 3 1 2 3 2 2 3
output:
ya ya tidak
result:
wrong answer 1st lines differ - expected: 'YES', found: 'ya'