답안 #1058572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058572 2024-08-14T11:07:33 Z Zbyszek99 Light Bulbs (EGOI24_lightbulbs) C++17
22 / 100
72 ms 684 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

int n;
int type[100][100];
int rep_[100][2][2];

bool was_[100][2];

int ask(vector<pii> v)
{
    string q = "?\n";
    set<pii> s;
    forall(it,v) s.insert(it);
    rep(i,n)
    {
        rep(j,n)
        {
            if(s.find({i,j}) == s.end())
            {
                q += '0';
            }
            else
            {
                q += '1';
            }
        }
        q += '\n';
    }
    cout << q;
    cout.flush();
    int ans;
    cin >> ans;
    cout.flush();
    return ans;
}

void solve()
{
    cin >> n;
    cout.flush();
    type[0][0] = 0;
    rep(i,n)
    {
        rep_[i][0][0] = -1;
        rep_[i][0][1] = -1;
        rep_[i][1][0] = -1;
        rep_[i][1][1] = -1;
    }
    rep(i,n)
    {
        if(i%2 == 0)
        {
            rep(j,n-1)
            {
                int ans = ask({{i,j},{i,j+1}});
                if(ans == n || ans == n*2)
                {
                    type[i][j+1] = type[i][j];
                }
                else
                {
                    type[i][j+1] = type[i][j] ^ 1;
                }
            }
            if(i != n-1)
            {
                int ans = ask({{i,n-1},{i+1,n-1}});
                if(ans == n || ans == n*2)
                {
                    type[i+1][n-1] = type[i][n-1];
                }
                else
                {
                    type[i+1][n-1] = type[i][n-1] ^ 1;
                }    
            }
        }
        else
        {
            for(int j = n-1; j >= 1; j--)
            {
                int ans = ask({{i,j},{i,j-1}});
                if(ans == n || ans == n*2)
                {
                    type[i][j-1] = type[i][j];
                }
                else
                {
                    type[i][j-1] = type[i][j] ^ 1;
                }
            }
            if(i != n-1)
            {
                int ans = ask({{i,0},{i+1,0}});
                if(ans == n || ans == 2*n)
                {
                    type[i+1][0] = type[i][0];
                }
                else
                {
                    type[i+1][0] = type[i][0] ^ 1;
                }    
            }
        }
    }
    bool was = false;
    rep(i,n)
    {
        rep(j,n)
        {
            if(rep_[i][1][type[i][j]] != -1)
            {
                was = true;
                if(ask({{i,rep_[i][1][type[i][j]]},{i,j}}) == n)
                {
                    if(type[i][j] == 1)
                    {
                        rep(k,n)
                        {
                            rep(u,n)
                            {
                                type[k][u] ^= 1;
                            }
                        }
                    }
                }
                else
                {
                    if(type[i][j] == 0)
                    {
                        rep(k,n)
                        {
                            rep(u,n)
                            {
                                type[k][u] ^= 1;
                            }
                        }
                    }
                }
                break;
            }
            if(rep_[j][0][type[i][j]] != -1)
            {
                was = true;
                if(ask({{rep_[i][1][type[i][j]],j},{i,j}}) == n)
                {
                    if(type[i][j] == 0)
                    {
                        rep(k,n)
                        {
                            rep(u,n)
                            {
                                type[k][u] ^= 1;
                            }
                        }
                    }
                }
                else
                {
                    if(type[i][j] == 1)
                    {
                        rep(k,n)
                        {
                            rep(u,n)
                            {
                                type[k][u] ^= 1;
                            }
                        }
                    }
                }
                break;
            }
            
            rep_[i][1][type[i][j]] = j;
            rep_[j][0][type[i][j]] = i;
        }
        if(was) break;
    }
    //  cout << "type\n";
    //  rep(i,n)
    //  {
    //      rep(j,n)
    //      {
    //          cout << type[i][j];
    //      }
    //      cout << "\n";
    //  }
    // cout << "type\n";
         cout << "!\n";
        int sum0 = 0;
        int sum1 = 0;
        rep(i,n)
        {
            rep(j,n)
            {
                if(type[i][j] == 1)
                {
                    if(!was_[j][1]) sum1++;
                    was_[j][1] = true;
                }
                else
                {
                    if(!was_[i][0]) sum0++;
                    was_[i][0] = true;    
                }
            }
        }
        rep(i,n)
        {
            was_[i][0] = false;
            was_[i][1] = false;
        }
   //     cout << sum0 << " " << sum1 << " sum\n";
        if(sum1 == n)
        {
            rep(i,n)
            {
                rep(j,n)
                {
                    if(type[i][j] == 1)
                    {
                        if(!was_[j][0]) cout << "1";
                        else cout << "0";
                        was_[j][0] = true;
                    }
                    else
                    {
                        cout << "0";
                    }
                }
                cout << "\n";
            }
            cout.flush();   
        }
        else
        {
            rep(i,n)
            {
                rep(j,n)
                {
                    if(type[i][j] == 0)
                    {
                        if(!was_[i][1]) cout << "1";
                        else cout << "0";
                        was_[i][1] = true;
                    }
                    else
                    {
                        cout << "0";
                    }
                }
                cout << "\n";
            }   
            cout.flush();
        }
    
}

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random();
    int t = 1;
 //   cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 440 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 0 ms 600 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Partially correct 1 ms 344 KB Partially correct
19 Partially correct 1 ms 344 KB Partially correct
20 Partially correct 1 ms 344 KB Partially correct
21 Partially correct 1 ms 344 KB Partially correct
22 Partially correct 0 ms 344 KB Partially correct
23 Partially correct 0 ms 344 KB Partially correct
24 Correct 1 ms 344 KB Output is correct
25 Partially correct 0 ms 344 KB Partially correct
26 Correct 1 ms 440 KB Output is correct
27 Partially correct 1 ms 344 KB Partially correct
28 Partially correct 0 ms 344 KB Partially correct
29 Partially correct 0 ms 344 KB Partially correct
30 Partially correct 0 ms 344 KB Partially correct
31 Partially correct 1 ms 344 KB Partially correct
32 Partially correct 1 ms 344 KB Partially correct
33 Partially correct 1 ms 344 KB Partially correct
34 Partially correct 0 ms 344 KB Partially correct
35 Partially correct 1 ms 344 KB Partially correct
36 Partially correct 1 ms 344 KB Partially correct
37 Partially correct 1 ms 344 KB Partially correct
38 Partially correct 0 ms 344 KB Partially correct
39 Partially correct 1 ms 344 KB Partially correct
40 Partially correct 1 ms 344 KB Partially correct
41 Partially correct 1 ms 344 KB Partially correct
42 Partially correct 0 ms 344 KB Partially correct
43 Partially correct 0 ms 344 KB Partially correct
44 Partially correct 1 ms 344 KB Partially correct
45 Partially correct 1 ms 380 KB Partially correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Partially correct 1 ms 344 KB Partially correct
53 Partially correct 1 ms 344 KB Partially correct
54 Partially correct 1 ms 428 KB Partially correct
55 Partially correct 1 ms 344 KB Partially correct
56 Partially correct 0 ms 344 KB Partially correct
57 Partially correct 1 ms 344 KB Partially correct
58 Partially correct 1 ms 344 KB Partially correct
59 Runtime error 72 ms 684 KB Execution killed with signal 13
60 Halted 0 ms 0 KB -