답안 #723968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723968 2023-04-14T14:26:52 Z PoPularPlusPlus Red-blue table (IZhO19_stones) C++17
100 / 100
37 ms 6120 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];
	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};
			}
		}
	}
	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:59:15: warning: 'pos.std::array<int, 3>::_M_elems[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |     res[i][j] = '+';
      |     ~~~~~~~~~~^~~~~
stones.cpp:63:20: warning: 'pos.std::array<int, 3>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |   for(int i = 0; i < pos[1]; i++){
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1336 KB Output is correct
2 Correct 26 ms 4424 KB Output is correct
3 Correct 22 ms 4624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1308 KB Output is correct
2 Correct 21 ms 3572 KB Output is correct
3 Correct 22 ms 2612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 30 ms 1336 KB Output is correct
6 Correct 26 ms 4424 KB Output is correct
7 Correct 22 ms 4624 KB Output is correct
8 Correct 26 ms 1308 KB Output is correct
9 Correct 21 ms 3572 KB Output is correct
10 Correct 22 ms 2612 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 21 ms 3156 KB Output is correct
13 Correct 23 ms 2600 KB Output is correct
14 Correct 16 ms 1880 KB Output is correct
15 Correct 37 ms 6120 KB Output is correct
16 Correct 19 ms 4564 KB Output is correct
17 Correct 8 ms 2132 KB Output is correct