제출 #373127

#제출 시각아이디문제언어결과실행 시간메모리
373127luciocfLamps (JOI19_lamps)C++14
0 / 100
2 ms364 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3+10; char a[maxn], b[maxn]; int solve[maxn][maxn][2]; int dp[maxn]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf(" %c", &a[i]); for (int i = 1; i <= n; i++) scanf(" %c", &b[i]); for (int l = 1; l <= n; l++) { solve[l][l][0] = (b[l] == '0' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '0' || b[r-1] == '1') solve[l][r][0] = solve[l][r-1][0]; else solve[l][r][0] = solve[l][r-1][0]+1; } solve[l][l][1] = (b[l] == '1' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '1' || b[r-1] == '0') solve[l][r][1] = solve[l][r-1][1]; else solve[l][r][1] = solve[l][r-1][1]+1; } } for (int i = 1; i <= n; i++) { dp[i] = n+1; if (a[i] == b[i]) dp[i] = min(dp[i], dp[i-1]); for (int j = i-1; j >= 0 && a[j+1] != b[j+1]; j--) dp[i] = min(dp[i], 1 + dp[j]); bool zero = 0, um = 1; for (int j = i-1; j >= 0; j--) { zero |= (a[j+1] == '0'); um |= (a[j+1] == '1'); dp[i] = min(dp[i], (zero ? 1 : 0) + solve[j+1][i][1] + dp[j]); dp[i] = min(dp[i], (um ? 1 : 0) + solve[j+1][i][0] + dp[j]); } } printf("%d\n", dp[n]); }

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

lamp.cpp: In function 'int main()':
lamp.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
lamp.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf(" %c", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~
lamp.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |   scanf(" %c", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...