답안 #493324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493324 2021-12-11T01:58:17 Z hollwo_pelw Gift (IZhO18_nicegift) C++17
0 / 100
1 ms 592 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out");
#endif
	int testcases = 1;
	cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 4e5 + 5;

int n, m, sz, pre[N], deg[N];

// pre[i] - pre[i - m] > 0
// pre[i - n] - pre[i] > 0 

void Hollwo_Pelw() {
	cin >> n >> m;
	sz = n + m - __gcd(n, m);
	
	fill(deg, deg + sz, 0);

	for (int i = 0; i < sz; i++)
		for (auto j : {i - m, i + n}) 
			if (0 <= j && j < sz) deg[j] ++;

	queue<int> q;

	for (int i = 0; i < sz; i++)
		if (!deg[i]) q.push(i);

	int cur = N;

	while (!q.empty()) {
		int i = q.front(); q.pop();

		pre[i] = cur --;

		for (auto j : {i - m, i + n}) 
			if (0 <= j && j < sz) 
				if (!(--deg[j])) q.push(j);
	}

	cout << sz - 1 << '\n';
	for (int i = 1; i < sz; i++)
		cout << pre[i] - pre[i - 1] << ' ';
	cout << '\n';
}

Compilation message

nicegift.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
nicegift.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Added number should be positive
2 Halted 0 ms 0 KB -