제출 #373181

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

컴파일 시 표준 에러 (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...