QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355749 | #7942. $K$ Subsequences | ngpin04# | WA | 49ms | 3948kb | C++14 | 1.5kb | 2024-03-17 05:37:15 | 2024-03-17 05:37:16 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int,int> ii;
const int INF = 1e9;
int t;
int n, k;
int A[100003];
int ans[100003];
bool cek(int x)
{
multiset<ii> st;
for(int i = 1; i <= k; i++) st.insert({0, i});
for(int i = 1; i <= n; i++)
{
if(A[i] == 1)
{
auto it = st.upper_bound({x-1, INF});
if(it == st.begin()) return 0;
--it;
ans[i] = it->se;
ii tmp = {it->fi+1, it->se};
st.erase(it);
st.insert(tmp);
}
else
{
auto it = --st.end();
ans[i] = it->se;
if(it->fi != 0)
{
ii tmp = {it->fi-1, it->se};
st.erase(it);
st.insert(tmp);
}
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> A[i];
int kir = 0, kan = n;
while(kir < kan)
{
int mid = (kir+kan)/2;
if(cek(mid)) kan = mid;
else kir = mid+1;
}
cek(kir);
// cout << kir << "\n";
for(int i = 1; i <= n; i++)
{
cout << ans[i] << " ";
} cout << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 3 2 1 -1 1 4 2 -1 1 1 -1 7 3 1 1 1 1 1 1 1 10 3 1 1 1 1 -1 -1 1 1 1 1 12 4 1 1 1 1 -1 -1 -1 -1 1 1 1 1
output:
2 2 2 2 2 1 2 3 3 3 2 2 2 1 3 3 2 2 3 2 3 2 1 1 4 3 2 1 4 3 2 1 4 3 2 1
result:
ok Correct (5 test cases)
Test #2:
score: 0
Accepted
time: 49ms
memory: 3612kb
input:
18434 10 1 -1 1 1 -1 -1 1 -1 -1 1 1 10 2 -1 -1 -1 1 1 -1 1 1 1 1 10 2 1 -1 -1 -1 -1 1 1 -1 1 1 10 7 1 1 -1 1 -1 1 1 -1 -1 1 9 1 -1 1 -1 1 1 -1 1 -1 1 8 1 -1 -1 -1 -1 1 1 -1 -1 10 3 -1 -1 -1 1 1 1 1 -1 -1 -1 9 1 1 -1 -1 1 -1 -1 -1 -1 -1 10 10 -1 1 1 1 1 1 1 1 1 1 10 4 -1 1 -1 1 -1 1 1 -1 1 1 9 3 1 1 ...
output:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 7 6 7 7 7 7 5 7 6 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 2 2 3 2 3 1 1 1 1 1 1 1 1 1 10 10 9 8 7 6 5 4 3 2 4 4 4 4 4 4 3 4 4 2 3 2 3 2 3 3 3 3 3 4 3 4 4 2 1 4 4 7 7 6 5 4 3 2 1 7 7 6 6 6 6 6 6 6 5 6 1 1 1 1 1 1 1 1 1 3...
result:
ok Correct (18434 test cases)
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 3948kb
input:
1 199996 3 1 -1 1 1 1 1 -1 -1 -1 1 1 -1 1 -1 1 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 -1 1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 -1 -1 1 1 -1 -1 1 -1 -1 -1 -1 -1...
output:
1
result:
wrong output format Unexpected end of file - int32 expected (test case 1)