# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395737 | CaroLinda | Red-blue table (IZhO19_stones) | C++14 | 75 ms | 1616 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)(x.size())
const int LOG = 20 ;
const int MAXN=2e5+10 ;
using namespace std ;
int T , N , M , K ;
void solve()
{
scanf("%d %d", &N, &M ) ;
K = (N+2)>>1 ;
vector<int> freq(N,M) ;
vector< vector<char> > grid( N , vector<char>(M,'+') ) ;
int bestAns = N ;
int ans = N+1 , L = 0 , id = 0 ;
bool ok = true ;
for(int i = 0 ; i < M ; i++ , ans++ )
{
int cnt = K ;
while( cnt-- && ok )
{
if( id == N ) id = L ;
grid[id][i] = '-' ;
freq[id]-- ;
if( freq[id]*2 <= M )
{
for(int j = i+1 ; j < M ; j++ ) grid[id][j] = '-' ;
K-- ;
L++ ;
ans-- ;
}
id++ ;
}
bestAns = max(ans, bestAns ) ;
}
printf("%d\n" , bestAns ) ;
for(int i = 0 ; i < N ; i++ )
for(int j = 0 ; j < M ; j++ ) grid[i][j] = '+' ;
if(bestAns > N)
{
K = (N+2)>>1 ;
L = id = 0 ;
ans = N+1 ;
for(int i = 0 ; i < M ; i++ , ans++ )
{
int cnt = K ;
while( cnt-- )
{
if( id == N ) id = L ;
grid[id][i] = '-' ;
freq[id]-- ;
if( freq[id]*2 <= M )
{
for(int j = i+1 ; j < M ; j++ ) grid[id][j] = '-' ;
K-- ;
L++ ;
ans-- ;
}
id++ ;
}
if( ans == bestAns ) break ;
}
}
for(int i = 0 ; i < N ; i++ , printf("\n") )
for(int j = 0 ; j < M ; j++ ) printf("%c", grid[i][j] ) ;
}
int main()
{
scanf("%d", &T ) ;
while(T--) solve() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |