#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
using namespace std;
const int MAX_N=1000010;
char c[MAX_N]; int gdzie[2*MAX_N], e[2];
int main(void) {
int n, m, i, j=0, k, mx=0;
assert(scanf("%d%d%s", &n, &m, c)==3);
for(i=0; i<n; ++i)
c[i]=(c[i]=='T'?2:1);
for(j=0; j<n; ++j) {
if(c[j]==1)
break;
}
memset(gdzie, -1, sizeof(int)*2*(n+1));
for(i=j; i<n; ++i) {
mx+=c[i]; gdzie[mx]=i;
e[mx&1]=max(e[mx&1], mx);
}
while(m--) {
assert(scanf("%d", &k)==1);
if(j==n) {
if((k&1) || k>(n<<1))
puts("NIE");
else
printf("%d %d\n", 1, k>>1);
}
else {
if(!(k&1) && k<=2*j)
printf("%d %d\n", 1, k>>1);
else if(k<=mx) {
if(gdzie[k]!=-1)
printf("%d %d\n", j+1, gdzie[k]+1);
else
printf("%d %d\n", j+2, gdzie[k+1]+1);
}
else {
if(k<=(j<<1)+e[k&1])
printf("%d %d\n", j-((k-e[k&1])>>1)+1, gdzie[e[k&1]]+1);
else
puts("NIE");
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
10 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
640 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
34 ms |
2044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
1656 KB |
Output is correct |
2 |
Correct |
144 ms |
6264 KB |
Output is correct |
3 |
Correct |
68 ms |
4216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1664 KB |
Output is correct |
2 |
Correct |
30 ms |
2168 KB |
Output is correct |
3 |
Correct |
70 ms |
4348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
3832 KB |
Output is correct |
2 |
Correct |
99 ms |
5496 KB |
Output is correct |
3 |
Correct |
140 ms |
7672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
234 ms |
10360 KB |
Output is correct |
2 |
Correct |
244 ms |
11512 KB |
Output is correct |
3 |
Correct |
270 ms |
13944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
10616 KB |
Output is correct |
2 |
Correct |
252 ms |
13816 KB |
Output is correct |
3 |
Correct |
278 ms |
15736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
712 ms |
20088 KB |
Output is correct |
2 |
Correct |
431 ms |
20600 KB |
Output is correct |
3 |
Correct |
464 ms |
26452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
21688 KB |
Output is correct |
2 |
Correct |
704 ms |
26104 KB |
Output is correct |
3 |
Correct |
362 ms |
30072 KB |
Output is correct |