Submission #1248326

#TimeUsernameProblemLanguageResultExecution timeMemory
1248326CodeLakVNBrunhilda’s Birthday (BOI13_brunhilda)C++20
25.56 / 100
19 ms1096 KiB
#include <bits/stdc++.h> using namespace std; #define task "main" #define no "NO" #define yes "YES" #define F first #define S second #define vec vector #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) const int MAX_N = (int)1e5 + 5; int n, q; int p[MAX_N], query[MAX_N]; namespace sub1 { bool valid() { return max({*max_element(query + 1, query + q + 1), q, n}) <= (int)1e4; } const int MAX_N = (int)1e4; int dp[2][MAX_N + 3]; void solve() { memset(dp, 0x3f, sizeof(dp)); FOR(i, 1, p[n] - 1) dp[0][i] = 1; FOR(i, 1, n) { int cur = (i & 1), pre = !cur; memset(dp[cur], 0x3f, sizeof(dp[cur])); FOR(x, 1, MAX_N) { dp[cur][x] = min(dp[pre][x], dp[pre][x - x % p[i]] + 1); // cout << i << ", " << x << ": " << dp[cur][x] << "\n"; } } FOR(i, 1, q) { int id = (n & 1), x = query[i]; if (dp[id][x] < dp[0][0]) cout << dp[id][x] << "\n"; else cout << "oo\n"; } } } namespace sub2 { bool valid() { return (q == 1); } void solve() { int x = query[1]; bool ok = 0; FOR(i, 1, n) if (x % p[i] != 0) ok = 1; if (!ok) { cout << "oo\n"; return; } int ans = 0; while (x) { int maxMod = 0; FOR(i, 1, n) maxMod = max(maxMod, x % p[i]); x -= maxMod; ans++; } cout << ans << "\n"; } } void solve() { cin >> n >> q; FOR(i, 1, n) cin >> p[i]; FOR(i, 1, q) cin >> query[i]; if (sub1::valid()) sub1::solve(); else if (sub2::valid()) sub2::solve(); } int32_t main() { if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool multitest = 0; int numTest = 1; if (multitest) cin >> numTest; while (numTest--) { solve(); } return 0; } /* Lak lu theo dieu nhac!!!! */

Compilation message (stderr)

brunhilda.cpp: In function 'int32_t main()':
brunhilda.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...