제출 #222587

#제출 시각아이디문제언어결과실행 시간메모리
222587_7_7_Lamps (JOI19_lamps)C++14
100 / 100
66 ms16120 KiB
#include <bits/stdc++.h> //#define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define forev(i, b, a) for(int i = (b); i >= (a); --i) #define forn(i, a, b) for(int i = (a); i <= (b); ++i) #define all(x) x.begin(), x.end() #define sz(s) (int)s.size() #define pb push_back #define ppb pop_back #define mp make_pair #define s second #define f first using namespace std; typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e6 + 11; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const db eps = 1e-12, pi = 3.14159265359; const ll INF = 1e18; int n, dp[N][3]; char s[N], t[N]; char f (char c, int j) { if (!j) return c; return '0' + j - 1; } int get (int i, int j, int k) { int res = 0; if (j != k && j)//we need to open new interval ++res; if ((i == 1 || f(s[i - 1], k) == t[i - 1]) && f(s[i], j) != t[i]) ++res; //if s[i - 1] = t[i - 1] and s[i] = t[i] then don't need to add anything //if s[i - 1] != t[i - 1] and s[i] = t[i] then we already added 1 before //if s[i - 1] != t[i - 1] and s[i] != t[i] then we just add i to the last interval of operation XOR //otherwise we need to add new operation XOR return res; } main () { scanf("%d\n%s\n%s", &n, s + 1, t + 1); dp[0][1] = dp[0][2] = inf; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 3; ++j) dp[i][j] = inf; for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) dp[i][j] = min(dp[i][j], dp[i - 1][k] + get(i, j, k)); } cout << min({dp[n][0], dp[n][1], dp[n][2]}); }

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

lamp.cpp:64:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
lamp.cpp: In function 'int main()':
lamp.cpp:69:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
      for (int j = 0; j < 3; ++j)
      ^~~
lamp.cpp:72:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for (int j = 0; j < 3; ++j)
   ^~~
lamp.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d\n%s\n%s", &n, s + 1, t + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...