제출 #71498

#제출 시각아이디문제언어결과실행 시간메모리
71498RezwanArefin01Linear Garden (IOI08_linear_garden)C++17
100 / 100
38 ms10572 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int N = 1e6 + 10; int f[N], n, M; char s[N]; int main(int argc, char const *argv[]) { scanf("%d %d", &n, &M); scanf(" %s", s); int len = strlen(s); f[0] = 1; for(int i = 1; i < N; i++) f[i] = f[i - 1] * 2ll % M; int idx = 1, bal = 0, mn = 0, mx = 0; #define add(x, y) {x += y; if(x >= M) x -= M;} #define sub(x, y) {x -= y; if(x < 0) x += M;} for(int i = 0; i < len; i++) { if(s[i] == 'L') { mx = max(mx, ++bal); } else { int bal2 = bal + 1; int mn2 = min(mn, bal2); int mx2 = max(mx, bal2); int rem = n - i - 1; mn = min(mn, --bal); if(mx2 - mn2 > 2) continue; if(mx2 - mn2 == 2) { if(mn2 < bal2 && bal2 < mx2){ add(idx, f[rem + 1 >> 1]); } else add(idx, f[rem >> 1]); } else { add(idx, f[rem >> 1]); add(idx, f[rem + 1 >> 1]); sub(idx, 1); } } } printf("%d\n", idx); }

컴파일 시 표준 에러 (stderr) 메시지

linear_garden.cpp: In function 'int main(int, const char**)':
linear_garden.cpp:40:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      add(idx, f[rem + 1 >> 1]); 
                 ~~~~^~~
linear_garden.cpp:23:26: note: in definition of macro 'add'
  #define add(x, y) {x += y; if(x >= M) x -= M;}
                          ^
linear_garden.cpp:44:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     add(idx, f[rem + 1 >> 1]);
                ~~~~^~~
linear_garden.cpp:23:26: note: in definition of macro 'add'
  #define add(x, y) {x += y; if(x >= M) x -= M;}
                          ^
linear_garden.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &M); 
  ~~~~~^~~~~~~~~~~~~~~~~
linear_garden.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", s);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...