Submission #173502

#TimeUsernameProblemLanguageResultExecution timeMemory
173502vexRed-blue table (IZhO19_stones)C++14
100 / 100
54 ms1408 KiB
#include <bits/stdc++.h> #define pb push_back #define pii pair<int,int> #define ll long long #define pll pair<ll,ll> #define poc first #define kraj second #define maxn 1055005 using namespace std; int n,m; int treba_red; int treba_kol; bool moze(int red,int kol) { int sad_red = treba_red - (m - kol); int sad_kol = treba_kol - (n - red); int sad_n = red; int sad_m = kol; if(sad_red <= 0 || sad_kol <= 0)return true; int uk_red = sad_red * sad_n; int manji_kol = uk_red / sad_m; int veci_kol = manji_kol + 1; int br_veci = uk_red % sad_m; if(br_veci > 0) { return sad_n - veci_kol >= sad_kol; } return sad_n - manji_kol >= sad_kol; } int br[1005]; void ispisi(int red,int kol) { cout<<red + kol<<"\n"; for(int i=1;i<=m;i++)br[i] = 0; int sad_red = treba_red - (m - kol); for(int i=1;i<=n;i++) { int treba = sad_red; int minn = 10005; for(int j=1;j<=kol;j++) { minn = min(br[j],minn); } for(int j=1;j<=m;j++) { if(j > kol) { cout<<"+"; } else if(i > red) { cout<<"-"; } else { if(treba <= 0) { cout<<"-"; } else { if(br[j] == minn || (kol - j + 1) == treba) { treba--; cout<<"+"; br[j]++; } else { cout<<"-"; } } } } cout<<"\n"; } } int main() { /*ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);*/ int t; cin>>t; while(t > 0) { t--; cin>>n>>m; treba_red = (m+2)/2; treba_kol = (n+2)/2; int maxx = 0; int maxx_red = 0; int maxx_kol = 0; for(int i=0;i<=n;i++) { for(int j=0;j<=m;j++) { if(i + j > maxx && moze(i,j)) { maxx = i + j; maxx_red = i; maxx_kol = j; } } } ispisi(maxx_red,maxx_kol); } 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...