Submission #577107

#TimeUsernameProblemLanguageResultExecution timeMemory
577107goodluck2020Brunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
244 ms80264 KiB
#define INPFILE "GROUP.INP" #define OUTFILE "GROUP.OUT" #include <bits/stdc++.h> using namespace std; bool maximise(int &a, int b) { return a < b ? a = b, true : false; } const int MAX = 1e7 + 1, INF = 0x3f3f3f3f; int n, Q, rmax[MAX], f[MAX]; bool used[MAX]; void input(void) { cin >> n >> Q; memset(rmax, 0, sizeof rmax); for (int i = 1; i <= n; i++) { int x; cin >> x; if (used[x]) continue; for (int j = x - 1; j < MAX; j += x) maximise(rmax[j], x - 1); maximise(rmax[MAX - 1], (MAX - 1) % x); } for (int i = MAX - 2; i >= 0; i--) maximise(rmax[i], rmax[i + 1] - 1); } int main(void) { if (fopen(INPFILE, "r")) { freopen(INPFILE, "r", stdin); freopen(OUTFILE, "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); input(); memset(f, 0x3f, sizeof f); f[0] = 0; for (int i = 1; i < MAX; i++) f[i] = f[i - rmax[i]] + 1; while (Q--) { int x; cin >> x; int ans = f[x]; if (ans >= INF) cout << "oo\n"; else cout << ans << '\n'; } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen(INPFILE, "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(OUTFILE, "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...