QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122610#6644. Red Black Gridinstallb#RE 0ms0kbC++142.7kb2023-07-10 20:15:362023-07-10 20:15:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 20:15:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-10 20:15:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int a[2005][2005];
int n,k;

void solve(){
    vector <pair <int,pair <int,int> > > G;
    cin >> n >> k;
    // special judge for N=3
    if(n == 3){
        if(k == 3){
            cout << "Possible\n";
            cout << "BRB\n";
            cout << "BBB\n";
            cout << "BBB\n";
            return;
        }
        if(k == 5){
            cout << "Possible\n";
            cout << "BRB\n";
            cout << "BBB\n";
            cout << "BBR\n";
            return;
        }
        if(k == 7){
            cout << "Possible\n";
            cout << "BRB\n";
            cout << "BBB\n";
            cout << "RBR\n";
            return;
        }
        if(k == 9){
            cout << "Possible\n";
            cout << "BRB\n";
            cout << "RBR\n";
            cout << "BBB\n";
            return;
        }
    }
    for(int i = 1;i <= n;i ++){
        for(int j = (i & 1) ? 1 : 2;j <= n;j += 2){
            if(i == 1 || j == 1 || i == n || j == n){
                if((i == 1 && j == 1) || (i == n && j == n) || (i == 1 && j == n) || (i == n && j == 1)) G.push_back({2,{i,j}});
                else G.push_back({3,{i,j}});
            }
            else G.push_back({4,{i,j}});
        }
    }
    sort(G.begin(),G.end());
    reverse(G.begin(),G.end());
    if(k > n * (n - 1)){
        k = n * (n - 1) * 2 - k;
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= n;j ++){
                a[i][j] = 1;
            }
        }
        for(int i = 1;i <= n;i ++){
            for(int j = (i & 1) ? 1 : 2;j <= n;j += 2){
                a[i][j] = 0;
            }
        }
    }
    else{
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= n;j ++){
                a[i][j] = 0;
            }
        }
    }
    for(auto [v,p] : G){
        auto [x,y] = p;
        if(k - v == 1 || k - v < 0) continue;
        k -= v; a[x][y] = 1;
    }
    if(k != 0){
        cout << "Impossible\n";
        assert(0);
        return;
    }
    cout << "Possible\n";
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= n;j ++){
            cout << (a[i][j] ? 'R' : 'B');
        }
        cout << '\n';
    }
}

int main(){
    ios::sync_with_stdio(false);
    int TC;
    cin >> TC;
    while(TC --){
        solve();
    }
    // for(int i = 3;i <= 50;i ++){
    //     for(int j = 0;j <= 2 * i * (i - 1);j ++){
    //         if(j == 1 || j + 1 == 2 * i * (i - 1)) continue;
    //         n = i; k = j;
    //         cout << n << ',' << k << endl; solve();
    //     }
    // }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2
3 6
3 1

output:

Possible
BBB
BRB
BBR

result: