Submission #338112

#TimeUsernameProblemLanguageResultExecution timeMemory
338112BeanZNice sequence (IZhO18_sequence)C++14
58 / 100
2036 ms49632 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 1e6 + 50; long long mod = 1e9 + 7; const int lim = 700; const int lg = 18; const int base = 311; const long double eps = 1e-6; ll n, m; vector<ll> node[N]; vector<ll> topo; ll vis[N], id[N]; void dfs(ll u, ll mid){ vis[u] = 1; for (auto j : node[u]){ if (vis[j] || j > mid) continue; dfs(j, mid); } topo.push_back(u); } bool chk(ll mid){ for (int i = 0; i <= mid; i++) vis[i] = 0; topo.clear(); for (int i = 0; i <= mid; i++){ if (vis[i]) continue; dfs(i, mid); } for (int i = 0; i < topo.size(); i++){ id[topo[i]] = i; } for (int i = 0; i <= mid; i++){ for (auto j : node[i]){ if (j > mid) continue; if (id[i] < id[j]) return false; } } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll t; cin >> t; while (t--){ cin >> n >> m; ll l = 1, h = 2e5 + 1; for (int i = 0; i <= h; i++) node[i].clear(); for (int i = 0; i <= h; i++){ if (i >= n) node[i - n].push_back(i); if (i >= m) node[i].push_back(i - m); } while (l <= h){ ll mid = (l + h) >> 1; if (chk(mid)) l = mid + 1; else h = mid - 1; } cout << h << endl; chk(h); for (int i = 1; i <= h; i++){ cout << id[i] - id[i - 1] << " "; } cout << endl; } } /* Ans: Out: */

Compilation message (stderr)

sequence.cpp: In function 'bool chk(int)':
sequence.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < topo.size(); i++){
      |                     ~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         freopen("test.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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...