제출 #1151711

#제출 시각아이디문제언어결과실행 시간메모리
1151711Ghulam_JunaidLight Bulbs (EGOI24_lightbulbs)C++20
80 / 100
75 ms472 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 105;
int n, mat[N][N];
set<pair<int, int>> V, H;

int ask(pair<int, int> x, pair<int, int> y){
    memset(mat, 0, sizeof mat);
    mat[x.first][x.second] = 1;
    mat[y.first][y.second] = 1;

    cout << "?" << endl;
    for (int i = 0; i < n; i ++){
        for (int j = 0; j < n; j ++)
            cout << mat[i][j];
        cout << endl;
    }

    int res;
    cin >> res;
    return res;
}

void solveV(){
    int i = 0;
    int j = 0;
    auto I = *V.begin();
    while (i < n and j < n){
        bool exist = 0;
        for (int k = 0; k < n; k ++)
            exist |= (V.find({k, j}) != V.end());
        if (exist){
            j++;
            continue;
        }

        exist = 0;
        for (int k = 0; k < n; k ++)
            exist |= (H.find({i, k}) != H.end());
        if (exist){
            i++;
            continue;
        }

        int x = ask(I, {i, j});
        if (x == 2 * n){
            V.insert({i, j});
            j++;
        }
        else{
            H.insert({i, j});
            i++;
        }
    }

    if (V.size() == n){
        memset(mat, 0, sizeof mat);
        cout << "!" << endl;
        for (auto [i, j] : V)
            mat[i][j] = 1;
        for (int i = 0; i < n; i ++){
            for (int j = 0; j < n; j ++)
                cout << mat[i][j];
            cout << endl;
        }
    }
    else if (H.size() == n){
        memset(mat, 0, sizeof mat);
        cout << "!" << endl;
        for (auto [i, j] : H)
            mat[i][j] = 1;
        for (int i = 0; i < n; i ++){
            for (int j = 0; j < n; j ++)
                cout << mat[i][j];
            cout << endl;
        }
    }
    else{
        cout << 1 / 0 << endl;
    }
}

void solveH(){
    int i = 0;
    int j = 0;
    auto I = *H.begin();
    while (i < n and j < n){
        bool exist = 0;
        for (int k = 0; k < n; k ++)
            exist |= (V.find({k, j}) != V.end());
        if (exist){
            j++;
            continue;
        }

        exist = 0;
        for (int k = 0; k < n; k ++)
            exist |= (H.find({i, k}) != H.end());
        if (exist){
            i++;
            continue;
        }

        int x = ask(I, {i, j});
        if (x == 2 * n){
            H.insert({i, j});
            i++;
        }
        else{
            V.insert({i, j});
            j++;
        }
    }

    if (V.size() == n){
        memset(mat, 0, sizeof mat);
        cout << "!" << endl;
        for (auto [i, j] : V)
            mat[i][j] = 1;
        for (int i = 0; i < n; i ++){
            for (int j = 0; j < n; j ++)
                cout << mat[i][j];
            cout << endl;
        }
    }
    else if (H.size() == n){
        memset(mat, 0, sizeof mat);
        cout << "!" << endl;
        for (auto [i, j] : H)
            mat[i][j] = 1;
        for (int i = 0; i < n; i ++){
            for (int j = 0; j < n; j ++)
                cout << mat[i][j];
            cout << endl;
        }
    }
    else{
        cout << 1 / 0 << endl;
    }
}

int main(){
    cin >> n;
    
    int a = ask({0, 0}, {0, 1});
    if (a == n){
        H.insert({0, 0});
        solveH();
        return 0;
    }

    if (a == 2 * n){
        V.insert({0, 0});
        V.insert({0, 1});
        solveV();
        return 0;
    }

    int b = ask({0, 0}, {0, 2});
    if (b == n){
        H.insert({0, 0});
        V.insert({0, 1});
        solveV();
        return 0;
    }

    if (b == 2 * n){
        V.insert({0, 0});
        V.insert({0, 2});
        H.insert({0, 1});
        solveV();
        return 0;
    }

    int c = ask({0, 1}, {0, 2});
    if (c == n){
        H.insert({0, 1});
        V.insert({0, 0});
        solveV();
        return 0;
    }

    if (c == 2 * n){
        V.insert({0, 1});
        V.insert({0, 2});
        H.insert({0, 0});
        solveV();
        return 0;
    }
    cout << 1/0 << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void solveV()':
Main.cpp:80:19: warning: division by zero [-Wdiv-by-zero]
   80 |         cout << 1 / 0 << endl;
      |                 ~~^~~
Main.cpp: In function 'void solveH()':
Main.cpp:139:19: warning: division by zero [-Wdiv-by-zero]
  139 |         cout << 1 / 0 << endl;
      |                 ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:191:14: warning: division by zero [-Wdiv-by-zero]
  191 |     cout << 1/0 << endl;
      |             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...