Submission #1105931

# Submission time Handle Problem Language Result Execution time Memory
1105931 2024-10-28T12:50:58 Z RiverFlow Towers (NOI22_towers) C++14
5 / 100
218 ms 74464 KB
#include <bits/stdc++.h>

#define nl "\n"
#define no "NO"
#define yes "YES"
#define fi first
#define se second
#define vec vector
#define task "main"
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())

using namespace std;

template<typename U, typename V> bool maxi(U &a, V b) {
    if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool mini(U &a, V b) {
    if (a > b) { a = b; return 1; } return 0;
}

const int mod = (int)1e9 + 7;

void prepare(); void main_code();

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    const bool MULTITEST = 0; prepare();
    int num_test = 1; if (MULTITEST) cin >> num_test;
    while (num_test--) { main_code(); }
}

void prepare() {};

const int N = (int)1e6 + 9;

pair<int, int> a[N], b[N];

vector<int> row[N];

vec<int> col[N];

void _fill(int rw, int j) {
    int c = a[j].fi;
    col[c].push_back(j);
    sort(all(col[c]), [&](int x, int y){
         return a[x].se < a[y].se;
    });
    if (sz(col[c]) == 3) {
        swap(col[c][1], col[c][2]);
        int t = col[c].back();
        col[c].pop_back();
        int nw = a[t].se;
        int &l = b[nw].fi, &r = b[nw].se;
        if (row[nw][l] == t) {
            ++l;
            if (l<r)
                _fill(nw, row[nw][l]);
        } else {
            --r;
            if (r>l)
                _fill(nw, row[nw][r]);
        }
    }

}
void main_code() {
    int n; cin >> n;
    vec<int> yy;
    for(int i = 0; i < n; ++i) {
        cin >> a[i].fi >> a[i].se;
        row[a[i].se].push_back(i);
    }
    const int MAX = N - 3;
    FOR(i, 0, MAX) if (sz(row[i])) {
        sort(row[i].begin(), row[i].end(), [&](int x, int y) {
             return a[x].se < a[y].se;
        });
        int m = sz(row[i]);
        b[i] = _mp(0, m - 1);
        _fill(i, row[i][0]);
        if (m != 1)
            _fill(i, row[i][1]);
    }
    vec<bool> use(n, 0);
    FOR(i, 0, MAX) if (sz(row[i])) {
        int l=b[i].fi, r=b[i].se;
        if (l<=r){
            use[row[i][l]]=use[row[i][r]]=1;
        }
    }
    string s;
    FOR(i,0,n-1){
        if(use[i])s.push_back('1');
        else s.push_back('0');
    }
    cout << s;

}


/*     Let the river flows naturally     */

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 51792 KB Output is correct
2 Correct 12 ms 51792 KB Output is correct
3 Correct 12 ms 53840 KB Output is correct
4 Correct 15 ms 53840 KB Output is correct
5 Correct 11 ms 53944 KB Output is correct
6 Correct 12 ms 51792 KB Output is correct
7 Correct 12 ms 53840 KB Output is correct
8 Correct 11 ms 51792 KB Output is correct
9 Correct 12 ms 51784 KB Output is correct
10 Correct 12 ms 51792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 51792 KB Output is correct
2 Correct 12 ms 51792 KB Output is correct
3 Correct 12 ms 53840 KB Output is correct
4 Correct 15 ms 53840 KB Output is correct
5 Correct 11 ms 53944 KB Output is correct
6 Correct 12 ms 51792 KB Output is correct
7 Correct 12 ms 53840 KB Output is correct
8 Correct 11 ms 51792 KB Output is correct
9 Correct 12 ms 51784 KB Output is correct
10 Correct 12 ms 51792 KB Output is correct
11 Incorrect 12 ms 55888 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 51576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 218 ms 74464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 51792 KB Output is correct
2 Correct 12 ms 51792 KB Output is correct
3 Correct 12 ms 53840 KB Output is correct
4 Correct 15 ms 53840 KB Output is correct
5 Correct 11 ms 53944 KB Output is correct
6 Correct 12 ms 51792 KB Output is correct
7 Correct 12 ms 53840 KB Output is correct
8 Correct 11 ms 51792 KB Output is correct
9 Correct 12 ms 51784 KB Output is correct
10 Correct 12 ms 51792 KB Output is correct
11 Incorrect 12 ms 55888 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 51792 KB Output is correct
2 Correct 12 ms 51792 KB Output is correct
3 Correct 12 ms 53840 KB Output is correct
4 Correct 15 ms 53840 KB Output is correct
5 Correct 11 ms 53944 KB Output is correct
6 Correct 12 ms 51792 KB Output is correct
7 Correct 12 ms 53840 KB Output is correct
8 Correct 11 ms 51792 KB Output is correct
9 Correct 12 ms 51784 KB Output is correct
10 Correct 12 ms 51792 KB Output is correct
11 Incorrect 12 ms 55888 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 51792 KB Output is correct
2 Correct 12 ms 51792 KB Output is correct
3 Correct 12 ms 53840 KB Output is correct
4 Correct 15 ms 53840 KB Output is correct
5 Correct 11 ms 53944 KB Output is correct
6 Correct 12 ms 51792 KB Output is correct
7 Correct 12 ms 53840 KB Output is correct
8 Correct 11 ms 51792 KB Output is correct
9 Correct 12 ms 51784 KB Output is correct
10 Correct 12 ms 51792 KB Output is correct
11 Incorrect 12 ms 55888 KB Output isn't correct
12 Halted 0 ms 0 KB -