Submission #28991

# Submission time Handle Problem Language Result Execution time Memory
28991 2017-07-18T03:50:43 Z kdh9949 Take-out (POI13_usu) C++14
22 / 100
189 ms 27728 KB
#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

usu.cpp: In function 'int main()':
usu.cpp:30:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%s", &n, &k, str + 1);
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3000 KB Output is correct
2 Incorrect 0 ms 3000 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3000 KB Output is correct
2 Incorrect 0 ms 3000 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3000 KB Output is correct
2 Incorrect 0 ms 3000 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3000 KB Output is correct
2 Incorrect 0 ms 3000 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3924 KB Output is correct
2 Correct 9 ms 3392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4192 KB Output is correct
2 Correct 36 ms 4040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 6168 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 7224 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 189 ms 27728 KB Output is correct
2 Correct 106 ms 6908 KB Output is correct
3 Correct 123 ms 6908 KB Output is correct
4 Incorrect 63 ms 8280 KB Unexpected end of file - int32 expected