답안 #711171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711171 2023-03-16T09:10:37 Z onlk97 Red-blue table (IZhO19_stones) C++14
100 / 100
31 ms 2232 KB
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,m;
    cin>>n>>m;
    int ans1=-1,rr;
    for (int r=0; r<=n; r++){
        int cnt=r,req=n/2+1-(n-r);
        if (req<=0) cnt+=m;
        else {
            int L=0,R=m;
            while (L<R){
                int mid=(L+R+1)/2;
                if (r*min(mid,m-m/2-1)>=mid*req) L=mid;
                else R=mid-1; 
            }
            cnt+=L;
        }
        if (cnt>ans1){
            ans1=cnt;
            rr=r;
        }
    }
    cout<<ans1<<'\n';
    int tt=ans1-rr;
    char op[n+1][m+1];
    for (int i=1; i<=n; i++){
        for (int j=1; j<=m; j++) op[i][j]=(i<=rr?'+':'-');
    }
    if (n-rr<n/2+1){
        int ut=min(ans1-rr,m-m/2-1);
        for (int j=1; j<=rr; j++){
            for (int k=(j-1)*ut; k<j*ut; k++) op[j][k%(ans1-rr)+1]='-';
        }
    }
    for (int i=1; i<=n; i++){
        for (int j=1; j<=m; j++) cout<<op[i][j];
        cout<<'\n';
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t;
    cin>>t;
    while (t--) solve();
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:25:9: warning: unused variable 'tt' [-Wunused-variable]
   25 |     int tt=ans1-rr;
      |         ^~
stones.cpp:6:17: warning: 'rr' may be used uninitialized in this function [-Wmaybe-uninitialized]
    6 |     int ans1=-1,rr;
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1212 KB Output is correct
2 Correct 23 ms 1740 KB Output is correct
3 Correct 21 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1276 KB Output is correct
2 Correct 25 ms 1564 KB Output is correct
3 Correct 18 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 24 ms 1212 KB Output is correct
6 Correct 23 ms 1740 KB Output is correct
7 Correct 21 ms 1772 KB Output is correct
8 Correct 31 ms 1276 KB Output is correct
9 Correct 25 ms 1564 KB Output is correct
10 Correct 18 ms 1356 KB Output is correct
11 Correct 6 ms 460 KB Output is correct
12 Correct 18 ms 1392 KB Output is correct
13 Correct 21 ms 1348 KB Output is correct
14 Correct 17 ms 1100 KB Output is correct
15 Correct 31 ms 2232 KB Output is correct
16 Correct 18 ms 1748 KB Output is correct
17 Correct 8 ms 916 KB Output is correct