제출 #332769

#제출 시각아이디문제언어결과실행 시간메모리
332769davitmargNice sequence (IZhO18_sequence)C++11
76 / 100
2068 ms71836 KiB
/* DavitMarg In a honky-tonk, Down in Mexico */ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <random> #include <bitset> #include <stack> #include <cassert> #include <iterator> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() #define fastIO ios::sync_with_stdio(false); cin.tie(0) using namespace std; const int N = 2 * 200005; int gcd(int a, int b) { while (a && b) { a %= b; swap(a, b); } return a + b; } int q, n, m, k, a[N], used[N], tin[N]; vector<int> t, g[N]; void dfs(int v) { used[v] = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (used[to]) continue; dfs(to); } //tin[v] = -t.size(); t.PB(v); } void check(int x) { t.clear(); for (int i = 0; i <= x; i++) g[i].clear(); for (int i = 0; i <= x; i++) { if (i - m >= 0) g[i - m].PB(i); if (i + n <= x) g[i + n].PB(i); } for (int i = 0; i <= x; i++) if (!used[i]) dfs(i); int v, to; for (int i = t.size() - 1; i >= 0; i--) { v = t[i]; a[v] = t.size() - i; for (int j = 0; j < g[v].size(); j++) { to = g[v][j]; a[to] = a[v] + 1; } } } int main() { fastIO; cin >> q; while (q--) { k = 0; cin >> n >> m; k = n + m - gcd(n, m) - 1; check(k); printf("%d\n", k); for (int i = 1; i <= k; i++) { printf("%d ", a[i] - a[i - 1]); used[i] = 0; } used[0] = 0; printf("\n"); } return 0; } /* */

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

sequence.cpp: In function 'void dfs(int)':
sequence.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 0; i < g[v].size(); i++)
      |                     ~~^~~~~~~~~~~~~
sequence.cpp: In function 'void check(int)':
sequence.cpp:82:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j = 0; j < g[v].size(); j++)
      |                         ~~^~~~~~~~~~~~~
#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...