Submission #723967

# Submission time Handle Problem Language Result Execution time Memory
723967 2023-04-14T14:26:01 Z PoPularPlusPlus Red-blue table (IZhO19_stones) C++17
100 / 100
37 ms 10060 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

bool remender(ll a , ll b){return a%b;}

//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);

void solve(){
	int n , m;
	cin >> n >> m;
	int dp[n+1][m+1],dp1[m+1][n+1];
	int mnn = m/2 + 1,mnm = n/2 + 1;
	int ans = 0;
	array<int,3> pos;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= mnn; j++){
			dp[i][j] = i;
			if(i <= n-mnm)dp[i][j] += j;
			int rem = m - j;
			if(rem){
			int total = i*mnn-j*i;
			int less = total / rem;
			int some = total % rem;
			if(less+1 <= n-mnm)dp[i][j] += some;
			if(less <= n-mnm)dp[i][j] += rem - some;
			}
			if(dp[i][j] > ans){
				ans = dp[i][j];
				pos = {0,i,j};
			}
		}
	}
	for(int i = 0; i <= m; i++){
		for(int j = 0; j <= mnm; j++){
			dp1[i][j] = i;
			if(i <= m-mnn)dp1[i][j] += j;
			int rem = n - j;
			if(rem){
			int total = i*mnm-i*j;
			int less = total / rem;
			int some = total % rem;
			if(less+1 <= m-mnn)dp1[i][j] += some;
			if(less <= m-mnn)dp1[i][j] += rem - some;
			}
			if(dp1[i][j] > ans){
				ans = dp1[i][j];
				pos = {1,i,j};
			}
		}
	}
	cout << ans << '\n';
	char res[n][m];
	if(pos[0] == 0){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				res[i][j] = '-';
			}
		}
		for(int i = 0; i < pos[1]; i++){
			for(int j = 0; j < pos[2]; j++){
				res[i][j] = '+';
			}
		}
		int left = pos[2] , cur = left;
		for(int i = 0; i < pos[1]; i++){
			int cnt = 0;
			while(cnt < mnn-pos[2]){
				cnt++;
				res[i][cur] = '+';
				cur++;
				if(cur == m)cur = left;
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++)cout << res[i][j];
			cout << '\n';
		}
	}
}

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

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:77:15: warning: 'pos.std::array<int, 3>::_M_elems[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |     res[i][j] = '+';
      |     ~~~~~~~~~~^~~~~
stones.cpp:75:20: warning: 'pos.std::array<int, 3>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |   for(int i = 0; i < pos[1]; i++){
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1404 KB Output is correct
2 Correct 30 ms 6988 KB Output is correct
3 Correct 33 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1412 KB Output is correct
2 Correct 24 ms 5680 KB Output is correct
3 Correct 24 ms 3884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 324 KB Output is correct
5 Correct 37 ms 1404 KB Output is correct
6 Correct 30 ms 6988 KB Output is correct
7 Correct 33 ms 7532 KB Output is correct
8 Correct 27 ms 1412 KB Output is correct
9 Correct 24 ms 5680 KB Output is correct
10 Correct 24 ms 3884 KB Output is correct
11 Correct 10 ms 492 KB Output is correct
12 Correct 26 ms 4864 KB Output is correct
13 Correct 24 ms 3788 KB Output is correct
14 Correct 18 ms 2596 KB Output is correct
15 Correct 30 ms 10060 KB Output is correct
16 Correct 22 ms 7448 KB Output is correct
17 Correct 12 ms 3416 KB Output is correct