Submission #395741

# Submission time Handle Problem Language Result Execution time Memory
395741 2021-04-28T20:12:09 Z andremfq Red-blue table (IZhO19_stones) C++17
100 / 100
129 ms 2232 KB
/*
gulosinho da Carol. vai passando nas colunas e deixando elas boas, e pra isso mantem a qtd de - de cada linha
*/
#include<bits/stdc++.h>
using namespace std;
 
const int MAXN = 1010;
 
int t;
int n, m;
int k, l;
int ans;
int in[MAXN];
char grid[MAXN][MAXN];
bool inv;
 
set<pair<int, int> > s;
 
int main(){
	scanf("%d", &t);
	while(t--){
		s.clear();
		scanf("%d %d", &n, &m);
		if(n < m) swap(n, m), inv = true;
		else inv = false;
		k = n / 2 + 1;
		l = m / 2 + 1;
		ans = n;
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++)
				grid[i][j] = (inv) ? '-' : '+';
			s.insert(make_pair(-m, i));
			in[i] = m;
		}
		
		for(int j = 1; j <= m; j++){
			vector<int> ids;
			bool flag = false;
			for(int _ = 0; _ < k; _++){
				ids.push_back(s.begin()->second);
				if(s.begin()->first == -l) flag = true;
				s.erase(s.begin());
			}
			if(flag) break;
			ans++;
			
			for(int i = 0; i < ids.size(); i++){
				int cur = ids[i];
				in[cur]--;
				s.insert(make_pair(-in[cur], cur));
				grid[cur][j] = (inv) ? '+' : '-';
			}
		}
		
		printf("%d\n", ans);
		if(inv) swap(n, m);
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				printf("%c", (inv) ? grid[j][i] : grid[i][j]);
			}
			printf("\n");
		}
	}
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int i = 0; i < ids.size(); i++){
      |                   ~~^~~~~~~~~~~~
stones.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
stones.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 1320 KB Output is correct
2 Correct 118 ms 1988 KB Output is correct
3 Correct 106 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 1352 KB Output is correct
2 Correct 124 ms 1788 KB Output is correct
3 Correct 97 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 368 KB Output is correct
5 Correct 114 ms 1320 KB Output is correct
6 Correct 118 ms 1988 KB Output is correct
7 Correct 106 ms 2048 KB Output is correct
8 Correct 110 ms 1352 KB Output is correct
9 Correct 124 ms 1788 KB Output is correct
10 Correct 97 ms 1556 KB Output is correct
11 Correct 25 ms 460 KB Output is correct
12 Correct 100 ms 1884 KB Output is correct
13 Correct 102 ms 2032 KB Output is correct
14 Correct 82 ms 1592 KB Output is correct
15 Correct 129 ms 2232 KB Output is correct
16 Correct 93 ms 1880 KB Output is correct
17 Correct 42 ms 1248 KB Output is correct