제출 #1323431

#제출 시각아이디문제언어결과실행 시간메모리
1323431adscodingRemittance (JOI19_remittance)C++20
15 / 100
14 ms2132 KiB
#include <bits/stdc++.h> #define fi first #define se second #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) #define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i) #define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i) #define all(x) x.begin(), x.end() #define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__) template<typename T> void __prine_one(const char *&s, const T &x) { while (*s == ' ') ++s; const char *p = s; int bal = 0; while (*s) { if (*s == '(') ++bal; else if (*s == ')') --bal; else if (*s == ',' && bal == 0) break; ++s; } cerr.write(p, s - p) << " = " << x; if (*s == ',') { cerr << " , "; ++s; } } template<typename... Args> void debug(const char *s, Args... args) { cerr << "[ "; int dummy[] = {0, (__prine_one(s, args), 0)...}; (void)dummy; cerr << " ]\n\n"; } template<class X, class Y> bool maximize(const X &a, const X &b) { if (a < b) { a = b; return true; } return false; } template<class X, class Y> bool minimize(const X &a, const X &b) { if (a > b) { a = b; return true; } return false; } // -------------------------------------------------------------------------------------------- const int maxn = 1e5 + 3; int n, a[maxn], b[maxn], c[maxn]; // -------------------------------------------------------------------------------------------- namespace sub1 { bool approve() { if (n > 7) return false; FOR(i, 1, n) if (a[i] > 7 || b[i] > 7) return false; return true; } vector<int> state; set<vector<int>> vis; bool DFS() { bool c = true; FOR(i, 0, n - 1) if (state[i] != b[i + 1]) { c = false; break; } if (c) return true; vis.insert(state); FOR(i, 0, n - 1) if (state[i] >= 2) { state[i] -= 2; state[(i + 1) % n]++; if (!vis.count(state) && DFS()) { return true; } state[i] += 2; state[(i + 1) % n]--; } return false; } bool solve() { FOR(i, 1, n) state.push_back(a[i]); return DFS(); } } namespace AC { bool solve() { bool improve = true; FOR(i, 0, n - 1) { a[i] = a[i + 1]; b[i] = b[i + 1]; } while (improve) { improve = false; bool c = true; FOR(i, 0, n - 1) { if (a[i] - b[i] >= 1 && a[i] >= 2) { ll diff = max((a[i] - b[i] + 1) >> 1, a[i] / 2); a[(i + 1) % n] += diff; a[i] -= diff << 1; improve = true; } } ll sum = 0; FOR(i, 0, n - 1) sum += a[i] - b[i]; if (sum < 0) return false; FOR(i, 0, n - 1) if (a[i] != b[i]) { c = false; break; } if (c) return true; // FOR(i, 0, n - 1) // cerr << a[i] << ' '; // cerr << endl; } return false; } } bool solve() { cin >> n; ll sum = 0; FOR(i, 1, n) { cin >> a[i] >> b[i]; sum += a[i] - b[i]; } if (sum < 0) return false; if (sub1 :: approve()) return sub1 :: solve(); return AC :: solve(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve() ? cout << "Yes" : cout << "No"; return 0; }

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

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