Submission #395739

#TimeUsernameProblemLanguageResultExecution timeMemory
395739CaroLindaRed-blue table (IZhO19_stones)C++14
42 / 100
73 ms1420 KiB
#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] = '+' ; freq[i] = M ; } 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)

stones.cpp: In function 'void solve()':
stones.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  scanf("%d %d", &N, &M ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |  scanf("%d", &T ) ;
      |  ~~~~~^~~~~~~~~~~
#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...