제출 #914560

#제출 시각아이디문제언어결과실행 시간메모리
914560davitmargTowers (NOI22_towers)C++14
11 / 100
1131 ms115640 KiB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair    
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

const int N = 1000006;

#define Y first.first
#define X first.second
#define I second
#define pt pair<pair<int,int>, int>

int n;
int ans[N];
int used_x[N], used_y[N];
pt p[N];
vector<pt> x[N], y[N];
int used[N];


void lesgo(pt a)
{
    ans[a.I] = 1;
    if (!y[a.Y].empty() && y[a.Y][0] == a)
    {
        pt last = a;
        for (int i = 0; i < y[a.Y].size(); i++)
        {
            pt b = y[a.Y][i];
            if(!x[b.X].empty() && !used[b.I] && (x[b.X][0] == b || x[b.X].back() == b))
				last = b;
            used[b.I] = 1;
        }

        ans[last.I] = 1;
        y[a.Y].clear();

        if(last != a)
            lesgo(last);
    }
    else if (!y[a.Y].empty() && y[a.Y].back() == a)
    {
        pt last = a;
        for (int i = (int)y[a.Y].size() - 1; i >= 0; i--)
        {
            pt b = y[a.Y][i];
			if (!x[b.X].empty() && !used[b.I] && (x[b.X][0] == b || x[b.X].back() == b))
                last = b;
            used[b.I] = 1;
        }

        ans[last.I] = 1;
        y[a.Y].clear();

        if (last != a)
            lesgo(last);
    }


    if (!x[a.X].empty() && x[a.X][0] == a)
    {
		pt last = a;
        for (int i = 0; i < x[a.X].size(); i++)
        {
			pt b = x[a.X][i];
			if (!y[b.Y].empty() && !used[b.I] && (y[b.Y][0] == b || y[b.Y].back() == b))
				last = b;
			used[b.I] = 1;
		}

		ans[last.I] = 1;
		x[a.X].clear();

		if(last != a)
			lesgo(last);
	}
    else if (!x[a.X].empty() && x[a.X].back() == a)
    {
		pt last = a;
        for (int i = (int)x[a.X].size() - 1; i >= 0; i--)
        {
			pt b = x[a.X][i];
            if (!y[b.Y].empty() && !used[b.I] && (y[b.Y][0] == b || y[b.Y].back() == b))
				last = b;
			used[b.I] = 1;
		}

		ans[last.I] = 1;
		x[a.X].clear();

        if (last != a)
            lesgo(last);
    }

    
}

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i].X >> p[i].Y;
        p[i].I = i;
    }

    for (int i = 1; i <= n; i++)
    {
        x[p[i].X].push_back(p[i]);
        y[p[i].Y].push_back(p[i]);
    }


    for (int i = 0; i < N; i++)
    {
        sort(all(x[i]), [](pt a, pt b) {return a.Y < b.Y; });
        sort(all(y[i]), [](pt a, pt b) {return a.X < b.X; });
    }

    sort(p + 1, p + 1 + n);


    for (int i = 1; i <= n; i++)
    {
        if(used[p[i].I])
            continue;
        lesgo(p[i]);
    }

    for (int i = 1; i <= n; i++)
        cout << ans[i];
    cout << endl;

}




int main()
{
    fastIO;
    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }

    return 0;
}

/*

4
1 10
1 5
1 1
4 5

*/

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

Main.cpp: In function 'void lesgo(std::pair<std::pair<int, int>, int>)':
Main.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < y[a.Y].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
Main.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int i = 0; i < x[a.X].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
#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...