답안 #683307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683307 2023-01-18T07:02:06 Z FatihSolak Red-blue table (IZhO19_stones) C++17
0 / 100
2000 ms 736 KB
#include <bits/stdc++.h>
#define N 1005
using namespace std;
char res[N][N];
void solve(){
    int a,b;
    cin >> a >> b;
    int ans = a;
    int bestid = 0;
    int bestid2 = a;
    for(int c = 1;c<=b;c++){
        int num = a - (a/2 + 1);
        int now = c;
        int best = 0;
        for(int d = 1;d<=a;d++){
            int nw = c;
            set<pair<int,int>> s;
            for(int i = 0;i<d;i++){
                if((b/2 + 1 - (b-c)) <= 0){
                    nw++;
                }
                else s.insert({-(b/2 + 1 - (b-c)),i});
            }
            for(int i = 0;i<c && s.size();i++){
                vector<pair<int,int>> use;
                while(s.size() && use.size() < num){
                    use.push_back(*s.begin());
                    s.erase(s.begin());
                }
                for(auto u:use){
                    u.first++;
                    //ans[u.second][i] = '+';
                    if(u.first)
                        s.insert(u);
                    else nw++;
                }
            }
            if(nw > now){
                now = nw;
                best = d;
            }
        }
        if(now > ans){
            ans = now;
            bestid = c;
            bestid2 = best;
        }
    }
    //cout << bestid << ' ' << bestid2 << endl;
    for(int i = 0;i<a;i++){
        for(int j = 0;j<bestid;j++){
            res[i][j] = '-';
        }
    }
    for(int i = 0;i<a;i++){
        for(int j = bestid;j<b;j++){
            res[i][j] = '+';
        }
    }
    int num = a - (a/2 + 1);
    set<pair<int,int>> s;
    for(int i = 0;i<bestid2;i++){
        if((b/2 + 1 - (b-bestid)) <= 0){
            continue;
        }
        s.insert({-(b/2 + 1 - (b-bestid)),i});
    }
    for(int i = 0;i<bestid && s.size();i++){
        vector<pair<int,int>> use;
        while(s.size() && use.size() < num){
            use.push_back(*s.begin());
            s.erase(s.begin());
        }
        for(auto u:use){
            u.first++;
            res[u.second][i] = '+';
            if(u.first)
                s.insert(u);
        }
    }
    cout << ans << '\n';
    for(int i = 0;i<a;i++){
        for(int j = 0;j<b;j++){
            cout << res[i][j] << ' ';
        }
        cout << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:26:46: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |                 while(s.size() && use.size() < num){
      |                                   ~~~~~~~~~~~^~~~~
stones.cpp:70:38: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |         while(s.size() && use.size() < num){
      |                           ~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 408 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2075 ms 736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2078 ms 672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -