Submission #169138

#TimeUsernameProblemLanguageResultExecution timeMemory
169138Nodir_BobievRed-blue table (IZhO19_stones)C++14
100 / 100
83 ms2296 KiB
# include <bits/stdc++.h> # define FILE using namespace std; int main(){ # ifdef FILEs freopen( "input.txt", "r", stdin ); freopen( "output.txt", "w", stdout ); # endif ios_base::sync_with_stdio( false ); int t; cin >> t; while( t -- ){ int n, m; cin >> n >> m; char a[n][m]; int ans = 0; if( n < m ){ ans = m ; for( int i = 0; i < n; i ++ ){ for( int j = 0; j < m; j ++ ){ a[i][j] = '-'; } } int cnt[m] = {}, mn = 0, cnt1 = m; for( int i = 0; i < n; i ++ ){ int q1 = m/2+1; for( int j = 0; j < m; j ++ ){ if( mn == (n-1)/2 ){ mn = -1; break; } if( !q1 )break; if( cnt[j] == mn ){ a[i][j] = '+'; cnt[j] ++; cnt1--; q1--; if( !cnt1 ){ cnt1 = m; mn++; } } } for( int j = 0; j < m; j ++ ){ if( mn == (n-1)/2 ){ mn = -1; break; } if( !q1 )break; if( cnt[j] == mn ){ a[i][j] = '+'; cnt[j] ++; cnt1--; q1--; if( !cnt1 ){ cnt1 = m; mn++; } } } if( q1 == 0 ) ans ++; if( mn == -1 ) break; } } else{ ans = n ; for( int i = 0; i < n; i++ ){ for( int j = 0; j < m; j ++ ){ a[i][j] = '+'; } } int cnt[n] = {}, mn = 0, cnt1 = n; for( int j = 0; j < m; j ++ ){ int q1 = n/2+1; for( int i = 0; i < n; i ++ ){ if( mn == (m-1)/2 ){ mn = -1; break; } if( !q1 )break; if( cnt[i] == mn ){ a[i][j] = '-'; cnt[i]++; cnt1--; q1--; if( !cnt1 ){ cnt1 = n; mn++; } } } for( int i = 0; i < n; i ++ ){ if( mn == (m-1)/2 ){ mn = -1; break; } if( !q1 )break; if( cnt[i] == mn ){ a[i][j] = '-'; cnt[i]++; cnt1--; q1--; if( !cnt1 ){ cnt1 = n; mn++; } } } if( q1 == 0 ) ans ++; if( mn == -1 ) break; } } cout << ans << endl; for( int i = 0; i < n; i ++ ){ for( int j = 0; j < m; j ++ ){ cout << a[i][j]; }cout << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...