Submission #29569

# Submission time Handle Problem Language Result Execution time Memory
29569 2017-07-20T06:42:53 Z 서규호(#1242) Lollipop (POI11_liz) C++14
73 / 100
433 ms 10808 KB
#include <bits/stdc++.h>
#include <unistd.h>

#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define lld long long
#define Inf 1000000000
#define Mod 1000000007
#define Linf 1000000000000000000LL
#define get gett

using namespace std;

int N,M,sum;
int s[1000002],e[1000002];
char a[1000002];

void process(int sum){
	for(int i=sum-2; i>=1; i-=2){
		if(a[s[i+2]-1] == 'T'){
			s[i] = s[i+2]+1;
			e[i] = e[i+2];
		}else if(a[e[i+2]-1] == 'T'){
			s[i] = s[i+2];
			e[i] = e[i+2]-1;
		}else{
			s[i] = s[i+2]+1;
			e[i] = e[i+2]-1;
		}
	}
}

int main(){
    //freopen("input.txt","r",stdin);
	scanf("%d %d",&N,&M);
	scanf("%s",a);
	int it = -1,it2;
	for(int i=0; i<N; i++){
		if(a[i] == 'W'){
			it = i;
			break;
		}
	}
	for(int i=N-1; i>=0; i--){
		if(a[i] == 'W'){
			it2 = i;
			break;
		}
	}
	for(int i=0; i<N; i++){
		if(a[i] == 'W') sum++;
		else sum += 2;
	}
	if(it != -1){
        s[sum] = 1; e[sum] = N;
        process(sum);
        if(it >= N-1-it2){
            sum--;
            sum -= (N-1-it2)*2;
            s[sum] = 1; e[sum] = it2;
        }else{
            sum--;
            sum -= (it*2);
            s[sum] = it+2; e[sum] = N;
        }
        process(sum);
	}
	for(int i=1; i<=M; i++){
		int x;
		scanf("%d",&x);
		if(it == -1){
			if(x%2 == 0 && x <= N*2) printf("1 %d\n",x/2);
			else puts("NIE");
		}else{
			if(s[x] == 0) puts("NIE");
			else printf("%d %d\n",s[x],e[x]);
		}
	}

	return 0;
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:39:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
liz.cpp:40:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",a);
               ^
liz.cpp:74:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
liz.cpp:61:21: warning: 'it2' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(it >= N-1-it2){
                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10808 KB Output is correct
2 Correct 0 ms 10808 KB Output is correct
3 Correct 0 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10808 KB Output is correct
2 Correct 0 ms 10808 KB Output is correct
3 Correct 0 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10808 KB Output is correct
2 Correct 0 ms 10808 KB Output is correct
3 Correct 9 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10808 KB Output is correct
2 Correct 3 ms 10808 KB Output is correct
3 Correct 3 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10808 KB Output is correct
2 Correct 9 ms 10808 KB Output is correct
3 Correct 46 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 10808 KB Output is correct
2 Correct 189 ms 10808 KB Output is correct
3 Correct 79 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 10808 KB Output is correct
2 Correct 29 ms 10808 KB Output is correct
3 Correct 96 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 10808 KB Output is correct
2 Correct 153 ms 10808 KB Output is correct
3 Correct 159 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 10808 KB Output is correct
2 Correct 306 ms 10808 KB Output is correct
3 Correct 389 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 10808 KB Output is correct
2 Correct 433 ms 10808 KB Output is correct
3 Runtime error 0 ms 10808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 10808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 10808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -