Submission #286836

# Submission time Handle Problem Language Result Execution time Memory
286836 2020-08-31T05:05:35 Z oolimry Red-blue table (IZhO19_stones) C++14
100 / 100
30 ms 4352 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef long long lint;
typedef pair<int,int> ii;

pair<int, vector<string> > solve(int rows, int cols){
	vector<string> res;
	
	for(int r = 0;r < rows;r++){
		res.push_back("");
		for(int c = 0;c < cols;c++){
			res.back() += '-';
		}
	}
	
	int ans = cols;
	vector<int> F;
	F.assign(cols, 0);
		
	int c = 0;
	int needcol = (cols / 2) + 1;
	int maxrow = ((rows-1) / 2);
	int row = 0;
	int take = 0;
	
	while(true){
		if(F[c] == maxrow) break;
		res[row][c] = '+';
		F[c]++;
		
		c++; if(c == cols) c = 0;
		take++;
		if(take % needcol == 0){
			row++;
			ans++;
		}
	}
	
	return {ans, res}; 
}

vector<string> trans(vector<string> O){
	int rows = sz(O[0]);
	int cols = sz(O);
	vector<string> res;
	
	for(int r = 0;r < rows;r++){
		res.push_back("");
		for(int c = 0;c < cols;c++){
			res.back() += '-';
		}
	}
	
	for(int r = 0;r < rows;r++){
		for(int c = 0;c < cols;c++){
			res[r][c] = O[c][r];
			if(res[r][c] == '-') res[r][c] = '+';
			else res[r][c] = '-';
		}
	}
	
	return res;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int Q; cin >> Q;
	while(Q--){
		int rows, cols; cin >> rows >> cols;
		
		if(rows <= cols){
			auto res = solve(rows, cols);
			cout << res.first << "\n";
			for(string s : res.second){
				cout << s << "\n";
			}
		}
		else{
			auto Rres = solve(cols, rows);
			auto res = trans(Rres.second);
			
			cout << Rres.first << "\n";
			for(string s : res){
				cout << s << "\n";
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1400 KB Output is correct
2 Correct 18 ms 2432 KB Output is correct
3 Correct 29 ms 3620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1408 KB Output is correct
2 Correct 13 ms 2180 KB Output is correct
3 Correct 12 ms 1836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 30 ms 1400 KB Output is correct
6 Correct 18 ms 2432 KB Output is correct
7 Correct 29 ms 3620 KB Output is correct
8 Correct 17 ms 1408 KB Output is correct
9 Correct 13 ms 2180 KB Output is correct
10 Correct 12 ms 1836 KB Output is correct
11 Correct 10 ms 640 KB Output is correct
12 Correct 27 ms 2764 KB Output is correct
13 Correct 27 ms 2184 KB Output is correct
14 Correct 16 ms 1368 KB Output is correct
15 Correct 16 ms 4352 KB Output is correct
16 Correct 11 ms 2688 KB Output is correct
17 Correct 12 ms 1768 KB Output is correct