제출 #56169

#제출 시각아이디문제언어결과실행 시간메모리
56169aquablitz11Linear Garden (IOI08_linear_garden)C++14
40 / 100
1584 ms28284 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int INF = 1e9; int n, m; char str[N]; int dp[N][14]; bool vis[N][14]; inline int add(int a, int b) { return (a+b)%m; } int pos(int mn, int mx, int bal) { if (mn == 0) { if (mx == 0) return 0; if (mx == 1) return 1+bal; if (mx == 2) return 3+bal; } else if (mn == -1) { if (mx == 0) return 7+bal; if (mx == 1) return 9+bal; } else { return 13+bal; } } int solve1(int i, int mn, int mx, int bal) { if (mx-mn > 2) return 0; if (i == n) return 1; int j = pos(mn, mx, bal); if (vis[i][j]) return dp[i][j]; return dp[i][j] = add(solve1(i+1, min(mn, bal-1), mx, bal-1), solve1(i+1, mn, max(mx, bal+1), bal+1)); } int solve2(int i, int mn, int mx, int bal) { if (i == n) return 1; if (str[i] == 'L') return solve2(i+1, min(mn, bal-1), mx, bal-1); else return add(solve1(i+1, min(mn, bal-1), mx, bal-1), solve2(i+1, mn, max(mx, bal+1), bal+1)); } int main() { scanf("%d%d %s", &n, &m, str); printf("%d\n", solve2(0, 0, 0, 0)); return 0; }

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

linear_garden.cpp: In function 'int pos(int, int, int)':
linear_garden.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
linear_garden.cpp: In function 'int main()':
linear_garden.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d %s", &n, &m, str);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...