제출 #1118468

#제출 시각아이디문제언어결과실행 시간메모리
1118468vjudge1Lamps (JOI19_lamps)C++17
0 / 100
24 ms10492 KiB
#include <bits/stdc++.h> using namespace std; #define TASK "Lamps" #define REP(i, n) for(int i = 1; i <= n; i++) #define FOR(i, a, b) for(auto i = a; i <= b; i++) #define FORD(i, a, b) for(auto i = a; i >= b; i--) template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; } template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; } using ii = pair<int, int>; #define fi first #define se second const int N = (int)1e6 + 7; using Bit = bitset<N>; vector<ii> save; Bit a, b; int n; int dp[N], lst[N]; void Read() { cin >> n >> a >> b; } void Solve() { Bit c = ~(a ^ b); cout << a << endl << b << endl << c << endl; n--; int l = 0; bool isFill = c[0]; REP(i, n) { if(!c[i]) isFill = 0; if(!isFill && b[i] != b[i - 1]) { save.push_back({l, i - 1}); l = i; isFill = c[i]; } } if(l != n) save.push_back({l, n}); l = 0; FOR(i, 0, n) { if(i > 0 && c[i] && !c[i - 1]) save.push_back({l, i - 1}); if(c[i]) l = i + 1; } if(!c[n]) save.push_back({l, n}); sort(save.begin(), save.end(), [&] (const ii& u, const ii& v) { return u.se < v.se || (u.se == v.se && u.fi < v.fi); } ); memset(dp, 0x3f, sizeof dp); // dp[0] = 0; FOR(i, 1, n) { if(!c[i - 1]) lst[i] = i - 1; else lst[i] = lst[i - 1]; // cout << i << ' ' << lst[i] << endl; } for(auto [L, R] : save) { // cout << lst[L] << ' ' << L << ' ' << R << endl; if(L == 0) dp[R] = 1; else minimize(dp[R], dp[lst[L]] + 1); } // cout << N - c.count() << endl; cout << dp[n] << endl; } signed main() { cin.tie(0)->ios_base::sync_with_stdio(0); if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin); if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } Read(); Solve(); return 0; }

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

lamp.cpp: In function 'int main()':
lamp.cpp:88:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...