제출 #587027

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

vector<vector<int>>v;
vector<pair<int,int>>loc;

int N,M;

void give_initial_chart(int n, int m, vector<int>r, vector<int>c) {
    N = n, M = m;
    v.resize(n);
    loc.resize(n*m);
    for(auto &z : v)
        z.resize(m);
    for(int i = 0 ; i < n*m ; i++)
        v[r[i]][c[i]] = i, loc[i] = {r[i], c[i]};
}

int swap_seats(int a, int b) {
    swap(v[loc[a].first][loc[a].second], v[loc[b].first][loc[b].second]);
    swap(loc[a], loc[b]);

    int sz = 0;

    int x1 = N, x2 = -1, y1 = M, y2 = -1;

    int ans = 0;

    while(sz < N*M) {

        //cout << sz << ' ' << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << '\n';

        x1 = min(x1, loc[sz].first), x2 = max(x2, loc[sz].first);
        y1 = min(y1, loc[sz].second), y2 = max(y2, loc[sz].second);

        ans += ((x2 - x1 + 1) * (y2 - y1 + 1) == sz+1 ? 1 : 0);
        sz++;
    }

    return ans;
}
#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...