답안 #29560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29560 2017-07-20T06:09:43 Z 시제연(#1241) Lollipop (POI11_liz) C++11
100 / 100
689 ms 21776 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, p, fk = -1;
int lol[4000100];
vector<int> loc;
char str[1000100];

bool good(int k) {
	if (fk<0) return false;
	if (~lol[fk]&&~lol[fk+k]) {
		printf("%d %d\n",lol[fk]+1,lol[fk+k]);
		return true;
	}
	int idx = upper_bound(loc.begin(),loc.end(),k)-loc.begin();
	if (idx==loc.size()) return false;
	int l = loc[idx];
	if (~lol[l-k]&&lol[l]) {
		printf("%d %d\n",lol[l-k]+1,lol[l]);
		return true;
	}
	return false;
}

int main() {
	int i, t = 1;

	scanf("%d%d",&n,&m);
	scanf("%s",str);
	memset(lol,-1,sizeof(lol));
	lol[0] = 0;
	for (i=0;i<n;i++) {
		if (str[i]=='T') {p+=2; lol[p] = i+1;}
		else {p++; lol[p] = i+1; loc.push_back(p); if (fk<0) fk = p;}
	}
	for (i=0;i<m;i++) {
		int k;
		scanf("%d",&k);
		if (~lol[k]) {
			printf("%d %d\n",1,lol[k]);
			continue;
		}
		if (!good(k)) { printf("NIE\n"); }
	}

    return 0;
}

Compilation message

liz.cpp: In function 'bool good(int)':
liz.cpp:17:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (idx==loc.size()) return false;
         ^
liz.cpp: In function 'int main()':
liz.cpp:27:9: warning: unused variable 't' [-Wunused-variable]
  int i, t = 1;
         ^
liz.cpp:29:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
liz.cpp:30:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
                 ^
liz.cpp:39:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k);
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18620 KB Output is correct
2 Correct 0 ms 18620 KB Output is correct
3 Correct 3 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18620 KB Output is correct
2 Correct 3 ms 18620 KB Output is correct
3 Correct 3 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18620 KB Output is correct
2 Correct 0 ms 18620 KB Output is correct
3 Correct 13 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 18620 KB Output is correct
2 Correct 13 ms 18620 KB Output is correct
3 Correct 0 ms 18760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18620 KB Output is correct
2 Correct 6 ms 18760 KB Output is correct
3 Correct 43 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 18620 KB Output is correct
2 Correct 193 ms 18892 KB Output is correct
3 Correct 96 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 18760 KB Output is correct
2 Correct 26 ms 19472 KB Output is correct
3 Correct 63 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 18620 KB Output is correct
2 Correct 109 ms 19088 KB Output is correct
3 Correct 233 ms 18760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 18760 KB Output is correct
2 Correct 363 ms 19088 KB Output is correct
3 Correct 369 ms 18892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 19472 KB Output is correct
2 Correct 479 ms 21776 KB Output is correct
3 Correct 493 ms 18760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 689 ms 18620 KB Output is correct
2 Correct 583 ms 21776 KB Output is correct
3 Correct 536 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 629 ms 19472 KB Output is correct
2 Correct 586 ms 21776 KB Output is correct
3 Correct 446 ms 18620 KB Output is correct