Submission #676872

# Submission time Handle Problem Language Result Execution time Memory
676872 2023-01-01T12:42:30 Z YENGOYAN Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 38760 KB
/*
	//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
	\\                                    //
	//  271828___182845__904523__53602__  \\
	\\  87___47____13______52____66__24_  //
	//  97___75____72______47____09___36  \\
	\\  999595_____74______96____69___67  //
	//  62___77____24______07____66__30_  \\
	\\  35___35____47______59____45713__  //
	//                                    \\
	\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
											  */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7, inf = 1e12;

vector<bool> vis;
vector<vector<int>> gp;
vector<int> order;

void dfs(int u) {
	if (u >= vis.size()) {
		cout << "Co sik apushe im arev!\n";
		return;
	}
	vis[u] = 1;
	for (int& v : gp[u]) {
		if (!vis[v]) {
			dfs(v);
		}
	}
	order.push_back(u);
}

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> top_order(int mid, int n, int m) {
	++mid;
	gp = vector<vector<int>> (mid);
	vis = vector<bool> (mid);
	for (int i = n; i < mid; ++i) gp[i].push_back(i - n);
	for (int i = m; i < mid; ++i) gp[i - m].push_back(i);
	order.clear();
	for (int i = 0; i < mid; ++i) {
		if (!vis[i]) dfs(i);
	}

	reverse(order.begin(), order.end());
	vector<int> pref(mid);
	for (int i = 0; i < order.size(); ++i) pref[order[i]] = i;
	//return {};
	vector<int> ans;
	for (int i = 1; i < mid; ++i) ans.push_back(pref[i] - pref[i - 1]);
	return ans;
}

bool isok(vector<int>& v, int n, int m) {
	ll s = 0;
	if (v.size() < m || v.size() < n) return 1;
	for (int i = 0; i < n; ++i) s += v[i];
	if (s >= 0) return 0;
	for (int i = n; i < v.size(); ++i) {
		s -= v[i - n], s += v[i];
		if (s >= 0) return 0;
	}
	s = 0;
	for (int i = 0; i < m; ++i) s += v[i];
	if (s <= 0) return 0;
	for (int i = m; i < v.size(); ++i) {
		s -= v[i - m], s += v[i];
		if (s <= 0) return 0;
	}
	return 1;
}

void solve() {
	int n, m; cin >> n >> m;
	int  l = 0, r = n + m;
	vector<int> ans;
	while (l + 1 < r) {
		int mid = (l + r) / 2;
		vector<int> v = top_order(mid, n, m);
		if (isok(v, n, m)) l = mid, ans = v;
		else r = mid;
	}
	//cout << l << "\n";
	cout << ans.size() << "\n";
	for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int _; cin >> _; while (_--)
		solve();
}

Compilation message

sequence.cpp: In function 'void dfs(int)':
sequence.cpp:46:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  if (u >= vis.size()) {
      |      ~~^~~~~~~~~~~~~
sequence.cpp: In function 'std::vector<int> top_order(int, int, int)':
sequence.cpp:80:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |  for (int i = 0; i < order.size(); ++i) pref[order[i]] = i;
      |                  ~~^~~~~~~~~~~~~~
sequence.cpp: In function 'bool isok(std::vector<int>&, int, int)':
sequence.cpp:89:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |  if (v.size() < m || v.size() < n) return 1;
      |      ~~~~~~~~~^~~
sequence.cpp:89:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |  if (v.size() < m || v.size() < n) return 1;
      |                      ~~~~~~~~~^~~
sequence.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for (int i = n; i < v.size(); ++i) {
      |                  ~~^~~~~~~~~~
sequence.cpp:99:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for (int i = m; i < v.size(); ++i) {
      |                  ~~^~~~~~~~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:118:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 324 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 11 ms 604 KB Ok
7 Correct 70 ms 1964 KB Ok
8 Correct 35 ms 1036 KB Ok
9 Correct 91 ms 2292 KB Ok
10 Correct 47 ms 1396 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 1 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 1 ms 320 KB Ok
11 Correct 1 ms 340 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 212 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 1 ms 320 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 925 ms 24368 KB Ok
7 Correct 779 ms 28976 KB Ok
8 Correct 1566 ms 36056 KB Ok
9 Correct 1127 ms 32700 KB Ok
10 Correct 687 ms 20500 KB Ok
11 Correct 1168 ms 33136 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 0 ms 212 KB Ok
16 Correct 1 ms 212 KB Ok
17 Correct 0 ms 212 KB Ok
18 Correct 1 ms 212 KB Ok
19 Correct 1 ms 212 KB Ok
20 Correct 0 ms 212 KB Ok
21 Correct 0 ms 212 KB Ok
22 Correct 1 ms 320 KB Ok
23 Correct 1 ms 340 KB Ok
24 Correct 11 ms 596 KB Ok
25 Correct 11 ms 708 KB Ok
26 Correct 14 ms 628 KB Ok
27 Correct 10 ms 612 KB Ok
28 Correct 9 ms 668 KB Ok
29 Correct 7 ms 564 KB Ok
30 Correct 8 ms 568 KB Ok
31 Correct 12 ms 704 KB Ok
32 Correct 13 ms 648 KB Ok
33 Correct 11 ms 768 KB Ok
34 Correct 26 ms 1048 KB Ok
35 Correct 26 ms 1024 KB Ok
36 Correct 25 ms 1004 KB Ok
37 Correct 31 ms 948 KB Ok
38 Correct 24 ms 1012 KB Ok
39 Correct 24 ms 932 KB Ok
40 Correct 30 ms 1064 KB Ok
41 Correct 25 ms 1024 KB Ok
42 Correct 27 ms 1000 KB Ok
43 Correct 26 ms 1012 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 1 ms 324 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 1 ms 340 KB Ok
17 Correct 1 ms 340 KB Ok
18 Correct 11 ms 604 KB Ok
19 Correct 70 ms 1964 KB Ok
20 Correct 35 ms 1036 KB Ok
21 Correct 91 ms 2292 KB Ok
22 Correct 47 ms 1396 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Correct 1 ms 212 KB Ok
27 Correct 0 ms 212 KB Ok
28 Correct 1 ms 212 KB Ok
29 Correct 1 ms 212 KB Ok
30 Correct 0 ms 212 KB Ok
31 Correct 0 ms 212 KB Ok
32 Correct 1 ms 320 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 11 ms 596 KB Ok
35 Correct 11 ms 708 KB Ok
36 Correct 14 ms 628 KB Ok
37 Correct 10 ms 612 KB Ok
38 Correct 9 ms 668 KB Ok
39 Correct 7 ms 564 KB Ok
40 Correct 8 ms 568 KB Ok
41 Correct 12 ms 704 KB Ok
42 Correct 13 ms 648 KB Ok
43 Correct 11 ms 768 KB Ok
44 Correct 26 ms 1048 KB Ok
45 Correct 26 ms 1024 KB Ok
46 Correct 25 ms 1004 KB Ok
47 Correct 31 ms 948 KB Ok
48 Correct 24 ms 1012 KB Ok
49 Correct 24 ms 932 KB Ok
50 Correct 30 ms 1064 KB Ok
51 Correct 25 ms 1024 KB Ok
52 Correct 27 ms 1000 KB Ok
53 Correct 26 ms 1012 KB Ok
54 Correct 608 ms 11804 KB Ok
55 Correct 791 ms 12452 KB Ok
56 Correct 701 ms 12624 KB Ok
57 Correct 488 ms 10876 KB Ok
58 Correct 689 ms 12244 KB Ok
59 Correct 618 ms 11072 KB Ok
60 Correct 487 ms 11004 KB Ok
61 Correct 504 ms 11760 KB Ok
62 Correct 850 ms 12212 KB Ok
63 Correct 541 ms 11184 KB Ok
64 Correct 739 ms 11952 KB Ok
65 Correct 675 ms 12532 KB Ok
66 Correct 561 ms 11552 KB Ok
67 Correct 453 ms 11564 KB Ok
68 Correct 631 ms 12188 KB Ok
69 Correct 1378 ms 20196 KB Ok
70 Correct 1323 ms 20636 KB Ok
71 Correct 1357 ms 21792 KB Ok
72 Correct 1302 ms 19996 KB Ok
73 Correct 1379 ms 22536 KB Ok
74 Correct 1303 ms 20884 KB Ok
75 Correct 1307 ms 21732 KB Ok
76 Correct 1320 ms 20152 KB Ok
77 Correct 1334 ms 21784 KB Ok
78 Correct 1337 ms 21680 KB Ok
79 Correct 1396 ms 22024 KB Ok
80 Correct 1359 ms 22440 KB Ok
81 Correct 1339 ms 22420 KB Ok
82 Correct 1361 ms 20652 KB Ok
83 Correct 1287 ms 22036 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 1 ms 340 KB Ok
3 Correct 0 ms 340 KB Ok
4 Correct 1 ms 340 KB Ok
5 Correct 1 ms 340 KB Ok
6 Correct 0 ms 340 KB Ok
7 Correct 1 ms 340 KB Ok
8 Correct 1 ms 340 KB Ok
9 Correct 1 ms 340 KB Ok
10 Correct 0 ms 340 KB Ok
11 Correct 1 ms 340 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 1 ms 324 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 1 ms 340 KB Ok
17 Correct 1 ms 340 KB Ok
18 Correct 11 ms 604 KB Ok
19 Correct 70 ms 1964 KB Ok
20 Correct 35 ms 1036 KB Ok
21 Correct 91 ms 2292 KB Ok
22 Correct 47 ms 1396 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Correct 1 ms 212 KB Ok
27 Correct 0 ms 212 KB Ok
28 Correct 1 ms 212 KB Ok
29 Correct 1 ms 212 KB Ok
30 Correct 0 ms 212 KB Ok
31 Correct 0 ms 212 KB Ok
32 Correct 1 ms 320 KB Ok
33 Correct 1 ms 340 KB Ok
34 Correct 0 ms 212 KB Ok
35 Correct 1 ms 212 KB Ok
36 Correct 1 ms 212 KB Ok
37 Correct 1 ms 320 KB Ok
38 Correct 1 ms 212 KB Ok
39 Correct 925 ms 24368 KB Ok
40 Correct 779 ms 28976 KB Ok
41 Correct 1566 ms 36056 KB Ok
42 Correct 1127 ms 32700 KB Ok
43 Correct 687 ms 20500 KB Ok
44 Correct 1168 ms 33136 KB Ok
45 Correct 11 ms 596 KB Ok
46 Correct 11 ms 708 KB Ok
47 Correct 14 ms 628 KB Ok
48 Correct 10 ms 612 KB Ok
49 Correct 9 ms 668 KB Ok
50 Correct 7 ms 564 KB Ok
51 Correct 8 ms 568 KB Ok
52 Correct 12 ms 704 KB Ok
53 Correct 13 ms 648 KB Ok
54 Correct 11 ms 768 KB Ok
55 Correct 26 ms 1048 KB Ok
56 Correct 26 ms 1024 KB Ok
57 Correct 25 ms 1004 KB Ok
58 Correct 31 ms 948 KB Ok
59 Correct 24 ms 1012 KB Ok
60 Correct 24 ms 932 KB Ok
61 Correct 30 ms 1064 KB Ok
62 Correct 25 ms 1024 KB Ok
63 Correct 27 ms 1000 KB Ok
64 Correct 26 ms 1012 KB Ok
65 Correct 608 ms 11804 KB Ok
66 Correct 791 ms 12452 KB Ok
67 Correct 701 ms 12624 KB Ok
68 Correct 488 ms 10876 KB Ok
69 Correct 689 ms 12244 KB Ok
70 Correct 618 ms 11072 KB Ok
71 Correct 487 ms 11004 KB Ok
72 Correct 504 ms 11760 KB Ok
73 Correct 850 ms 12212 KB Ok
74 Correct 541 ms 11184 KB Ok
75 Correct 739 ms 11952 KB Ok
76 Correct 675 ms 12532 KB Ok
77 Correct 561 ms 11552 KB Ok
78 Correct 453 ms 11564 KB Ok
79 Correct 631 ms 12188 KB Ok
80 Correct 1378 ms 20196 KB Ok
81 Correct 1323 ms 20636 KB Ok
82 Correct 1357 ms 21792 KB Ok
83 Correct 1302 ms 19996 KB Ok
84 Correct 1379 ms 22536 KB Ok
85 Correct 1303 ms 20884 KB Ok
86 Correct 1307 ms 21732 KB Ok
87 Correct 1320 ms 20152 KB Ok
88 Correct 1334 ms 21784 KB Ok
89 Correct 1337 ms 21680 KB Ok
90 Correct 1396 ms 22024 KB Ok
91 Correct 1359 ms 22440 KB Ok
92 Correct 1339 ms 22420 KB Ok
93 Correct 1361 ms 20652 KB Ok
94 Correct 1287 ms 22036 KB Ok
95 Correct 1552 ms 28940 KB Ok
96 Execution timed out 2067 ms 38760 KB Time limit exceeded
97 Halted 0 ms 0 KB -