제출 #378890

#제출 시각아이디문제언어결과실행 시간메모리
378890abc864197532Nice sequence (IZhO18_sequence)C++17
15 / 100
1790 ms17048 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define pii pair<int, int> #define pll pair<lli, lli> #define X first #define Y second #define pb push_back #define eb emplace_back #define mp make_pair #define test(x) cout << #x << ' ' << x << endl #define printv(x) {\ for (auto a : x) cout << a << ' ';\ cout << endl;\ } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() vector <int> pre_ans; bool ask(int n, int m, int N) { vector <int> g[N + 1]; vector <int> in(N + 1, 0); for (int i = 0; i + n <= N; ++i) { g[i + n].pb(i); in[i]++; } for (int i = 0; i + m <= N; ++i) { g[i].pb(i + m); in[i + m]++; } queue <int> q; pre_ans.clear(); for (int i = 0; i <= N; ++i) if (!in[i]) q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); pre_ans.pb(v); for (int u : g[v]) { --in[u]; if (!in[u]) q.push(u); } } return pre_ans.size() == N + 1; } void solve() { int n, m; cin >> n >> m; int l = min(n, m) - 1, r = min(n, m) * 2 + 1; while (r - l > 1) { int mid = l + r >> 1; if (ask(n, m, mid)) l = mid; else r = mid; } ask(n, m, l); cout << l << endl; vector <int> pre(l + 1, 0); int t = 0; for (int i : pre_ans) pre[i] = t++; for (int i = 1; i <= l; ++i) cout << pre[i] - pre[i - 1] << ' '; if (l) cout << endl; } int main () { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) solve(); }

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

sequence.cpp: In function 'bool ask(int, int, int)':
sequence.cpp:43:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |     return pre_ans.size() == N + 1;
      |            ~~~~~~~~~~~~~~~^~~~~~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:51:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         int mid = l + r >> 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...