제출 #1043542

#제출 시각아이디문제언어결과실행 시간메모리
1043542Zicrus자리 배치 (IOI18_seats)C++17
17 / 100
4043 ms55724 KiB
#include <bits/stdc++.h>
#include "seats.h"
using namespace std;

typedef long long ll;

int n, w, h;
vector<int> x, y;
vector<int> le, ri, to, bo;
vector<bool> poss;
int res;

void give_initial_chart(int h1, int w1, vector<int> r, vector<int> c) {
    w = w1; h = h1;
    n = h*w;
    x = c; y = r;

    le = vector<int>(n);
    ri = vector<int>(n);
    to = vector<int>(n);
    bo = vector<int>(n);
    poss = vector<bool>(n);

    res = 1;
    poss[0] = true;
    int left = x[0], right = x[0], top = y[0], bot = y[0];
    le[0] = left; ri[0] = right; to[0] = top; bo[0] = bot;
    for (int i = 1; i < n; i++) {
        le[i] = left = min(left, x[i]);
        ri[i] = right = max(right, x[i]);
        to[i] = top = min(top, y[i]);
        bo[i] = bot = max(bot, y[i]);
        if ((right-left+1) * (bot-top+1) == i+1) {
            res++;
            poss[i] = true;
        }
    }
}

int swap_seats(int a, int b) {
    swap(x[a], x[b]);
    swap(y[a], y[b]);
    if (a > b) swap(a, b);
    int left = le[max(0,a-1)], right = ri[max(0,a-1)], top = to[max(0,a-1)], bot = bo[max(0,a-1)];
    if (a == 0) {
        le[0] = left = x[0]; ri[0] = right = x[0];
        to[0] = top = y[0]; bo[0] = bot = y[0];
    }
    for (int i = max(1,a); i < b; i++) {
        res -= poss[i];
        le[i] = left = min(left, x[i]);
        ri[i] = right = max(right, x[i]);
        to[i] = top = min(top, y[i]);
        bo[i] = bot = max(bot, y[i]);
        if ((right-left+1) * (bot-top+1) == i+1) {
            res++;
            poss[i] = true;
        }
        else poss[i] = false;
    }
    return res;
}
#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...