Submission #29521

# Submission time Handle Problem Language Result Execution time Memory
29521 2017-07-20T04:54:41 Z 김동현(#1239) Lollipop (POI11_liz) C++14
100 / 100
666 ms 22528 KB
#include <bits/stdc++.h>
using namespace std;

int n, q, l, r, a[1000010], al[2000010], ar[2000010], tr;
char str[1000010];

int main(){
	scanf("%d%d%s", &n, &q, str + 1);
	l = n + 1;
	for(int i = 1; i <= n; i++){
		a[i] = (str[i] == 'W') ? 1 : 2;
		if(a[i] == 1){
			l = min(l, i);
			r = max(r, i);
		}
	}
	if(l == n + 1){
		for(int i = 2; i <= 2 * n; i++){
			al[i] = 1;
			ar[i] = i / 2;
		}
	}
	else{
		if(n + 1 - r < l){
			reverse(a + 1, a + n + 1);
			tr = 1;
			l = n + 1 - r;
		}
		int tl = l, tr = l, sum = 1;
		al[1] = ar[1] = l;
		for(sum++; l < tl || tr < n; sum++){
			if(l < tl) tl--;
			else{
				tr++;
				if(a[tr] == 2) tl++;
			}
			al[sum] = tl;
			ar[sum] = tr;
		}
		for(sum++; tl >= 1; sum += 2){
			tl--;
			al[sum] = tl;
			ar[sum] = tr;
		}
	}
	for(int x; q--; ){
		scanf("%d", &x);
		if(!al[x]) puts("NIE");
		else if(!tr) printf("%d %d\n", al[x], ar[x]);
		else printf("%d %d\n", n + 1 - ar[x], n + 1 - al[x]);
	}
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:8:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%s", &n, &q, str + 1);
                                  ^
liz.cpp:47:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22528 KB Output is correct
2 Correct 0 ms 22528 KB Output is correct
3 Correct 0 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22528 KB Output is correct
2 Correct 0 ms 22528 KB Output is correct
3 Correct 0 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22528 KB Output is correct
2 Correct 0 ms 22528 KB Output is correct
3 Correct 9 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 22528 KB Output is correct
2 Correct 3 ms 22528 KB Output is correct
3 Correct 3 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 22528 KB Output is correct
2 Correct 9 ms 22528 KB Output is correct
3 Correct 33 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 22528 KB Output is correct
2 Correct 186 ms 22528 KB Output is correct
3 Correct 73 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 22528 KB Output is correct
2 Correct 23 ms 22528 KB Output is correct
3 Correct 86 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 22528 KB Output is correct
2 Correct 156 ms 22528 KB Output is correct
3 Correct 173 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 22528 KB Output is correct
2 Correct 313 ms 22528 KB Output is correct
3 Correct 333 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 323 ms 22528 KB Output is correct
2 Correct 393 ms 22528 KB Output is correct
3 Correct 416 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 22528 KB Output is correct
2 Correct 586 ms 22528 KB Output is correct
3 Correct 456 ms 22528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 22528 KB Output is correct
2 Correct 666 ms 22528 KB Output is correct
3 Correct 406 ms 22528 KB Output is correct