# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28991 | kdh9949 | Take-out (POI13_usu) | C++14 | 189 ms | 27728 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct Dat{
int *p, b, c;
};
int n, k;
char str[1000010];
stack<Dat> st, nst;
void upd(int i){
st.top().p[st.top().b + st.top().c] = i;
if(str[i] == 'b') st.top().b++;
else st.top().c++;
}
void top(int i){
int *p = new int[k + 1];
st.push({p, 0, 0});
upd(i);
}
void pop(){
nst.push(st.top());
st.pop();
}
int main(){
scanf("%d%d%s", &n, &k, str + 1);
for(int i = 1; i <= n; i++){
if(st.empty()) top(i);
else if(str[i] == 'b'){
if(st.top().b == k) top(i);
else upd(i);
if(st.top().b + st.top().c == k + 1){
pop();
}
}
else{
if(st.top().c == 1) top(i);
else upd(i);
if(st.top().b + st.top().c == k + 1){
pop();
}
}
}
while(!nst.empty()){
for(int i = 0; i <= k; i++) printf("%d ", nst.top().p[i]);
puts("");
nst.pop();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |