Submission #217953

# Submission time Handle Problem Language Result Execution time Memory
217953 2020-03-31T10:16:26 Z Kalam Lollipop (POI11_liz) C++11
100 / 100
503 ms 41940 KB
// KALAM
# include<bits/stdc++.h>

using namespace std;

const int N = 2000000 + 77;
int n , q , ps[N] , L[N] , R[N];
char S[N];
inline int Get(int l , int r) {
   if(l > r) return 0;
   return ps[r] - ps[l - 1];
}
int main() {
   scanf("%d %d" , & n , & q);
   scanf("%s" , S + 1);
   for(int i = 1;i <= n;++ i)
      ps[i] = ps[i - 1] + 1 + (S[i] == 'T');
   for(int i = 1;i <= n;++ i)
      L[Get(1 , i)] = 1 , R[Get(1 , i)] = i , L[Get(i , n)] = i , R[Get(i , n)] = n;
   int best_i = -1;
   for(int i = 1;i <= n;++ i)
      if(S[i] == 'W' && (best_i < 0 || max(ps[i] , ps[n] - ps[i - 1]) > max(ps[best_i] , ps[n] - ps[best_i - 1])))
         best_i = i;
   for(int i = best_i;i <= n;++ i)
      L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
   for(int i = best_i;i > 0;-- i)
      L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
   -- best_i;
   if(best_i > 0 && best_i <= n) {
      for(int i = best_i;i <= n;++ i)
         L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
      for(int i = best_i;i > 0;-- i)
         L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
   }
   best_i += 2;
   if(best_i > 0 && best_i <= n) {
      for(int i = best_i;i <= n;++ i)
         L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
      for(int i = best_i;i > 0;-- i)
         L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
   }
   while(q --) {
      int x;
      scanf("%d" , & x);
      if(L[x] == 0) printf("NIE\n");
      else printf("%d %d\n" , L[x] , R[x]);
   }
   return 0;
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:14:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d" , & n , & q);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~
liz.cpp:15:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s" , S + 1);
    ~~~~~^~~~~~~~~~~~~~
liz.cpp:44:12: 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 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 9 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1152 KB Output is correct
2 Correct 12 ms 1144 KB Output is correct
3 Correct 41 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2808 KB Output is correct
2 Correct 148 ms 8312 KB Output is correct
3 Correct 73 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2936 KB Output is correct
2 Correct 36 ms 2552 KB Output is correct
3 Correct 86 ms 5380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7032 KB Output is correct
2 Correct 105 ms 6904 KB Output is correct
3 Correct 147 ms 10488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 18168 KB Output is correct
2 Correct 248 ms 17912 KB Output is correct
3 Correct 280 ms 21880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 19704 KB Output is correct
2 Correct 300 ms 23160 KB Output is correct
3 Correct 340 ms 27384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 38892 KB Output is correct
2 Correct 420 ms 36532 KB Output is correct
3 Correct 458 ms 36984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 41940 KB Output is correct
2 Correct 484 ms 34808 KB Output is correct
3 Correct 382 ms 40060 KB Output is correct