Submission #1302344

#TimeUsernameProblemLanguageResultExecution timeMemory
1302344ndquangTowers (NOI22_towers)C++20
0 / 100
102 ms18276 KiB
#include<bits/stdc++.h>
#define nl 1000005
using namespace std;

int n;
int x[nl], y[nl];

namespace Subtask2 {

    void Solve() {

        string res = "";
        for( int mask = 1; mask < ( 1<<n ); mask ++ ) {

            bool test = true;
            vector<bool> used( n+1, false );
            vector<int> cntX( n+1, 0 ), cntY( n+1, 0 );

            for( int i = 0; i < n; i ++ )
            if(( mask >> i ) & 1) {

                used[i+1] = true;

                cntX[x[i+1]] ++ ;
                if( cntX[x[i+1]] > 2 ) {

                    test = false;
                    break;
                }

                cntY[y[i+1]] ++ ;
                if( cntY[y[i+1]] > 2 ) {

                    test = false;
                    break;
                }
            }

            if( test ) {

                for( int i = 1; i <= n; i ++ ) {

                    if( used[i] ) continue;

                    bool okX1 = false;
                    bool okX2 = false;
                    bool okX = false;

                    for( int j = 1; j <= n; j ++ ) if( j != i ) {

                        if( !used[j] ) continue;
                        if( x[i] == x[j] ) {

                            if( y[j] < y[i] ) okX1 = true;
                            if( y[j] > y[i] ) okX2 = true;
                        }

                        okX = okX1 & okX2;
                        if( okX ) break;
                    }

                    bool okY1 = false;
                    bool okY2 = false;
                    bool okY = false;

                    for( int j = 1; j <= n; j ++ ) if( j != i ) {

                        if( !used[j] ) continue;
                        if( y[i] == y[j] ) {

                            if( x[j] < x[i] ) okY1 = true;
                            if( x[j] > x[i] ) okY2 = true;
                        }

                        okY = okY1 & okY2;
                        if( okY ) break;
                    }

                    if( !okX && !okY ) {

                        test = false;
                        break;
                    }
                }
            }

            if( test ) {

                for( int i = 1; i <= n; i ++ )
                    if( used[i] ) res += "1";
                    else          res += "0";

                break;
            }
        }

        cout << res << "\n";
    }
}

int main() {
    ios_base :: sync_with_stdio( false );
    cin.tie( NULL ); cout.tie( NULL );

    #define File "SLAMP"
    if( fopen( File ".inp", "r" ) ) {

        freopen( File ".inp", "r", stdin );
        freopen( File ".out", "w", stdout );
    }

    cin >> n;
    for( int i = 1; i <= n; i ++ )
        cin >> x[i] >> y[i];

    if( n <= 16 )
        Subtask2 :: Solve();


    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen( File ".inp", "r", stdin );
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen( File ".out", "w", stdout );
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...