이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
#include<vector>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define x first
#define y second
/*
for down - just real distances from down (optional also for left) -> O(n)
for up - just real distances, or such that together it's distance between two -> O(n)+O(n^2)
after I have up and down - O(n^2) //optional - O(nlogu), with segmentree sparse/coordination, then O(n^4 logU)
then O(n^5), or if r<=40 -> O(40*40*40*n)
which is 60 points
*/
int deb = 0;
int Time_To_Fool_The_Lab(int r, int c, int n, vector<int> X, vector<int> Y) {
set<int> st_down,st_up, st_sum;
for (int i = 0; i < n; i++) {
st_down.insert(X[i] - 1);
}
for (int i = 0; i < n; i++) {
st_up.insert(r - X[i]);
for (int j = 0; j < n; j++) if (X[i] > X[j]) st_sum.insert(X[i] - X[j]-1);
}
vector<pi> v(n); for (int i = 0; i < n; i++) v[i] = { Y[i],X[i] };
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) swap(v[i].x, v[i].y);
int res = 2e9;
for (int down : st_down) {
set<int> nst_up = st_up;
for (int k : st_sum) if(k-down>=0) nst_up.insert(k - down);
for (int up : nst_up) {
set<int> intres;
intres.insert(1); intres.insert(r);
for (int i = 0; i < n; i++) {
if (X[i] - down - 1 > 0) intres.insert(X[i] - down - 1);
if (X[i] + up + 1 <= r) intres.insert(X[i] + up + 1);
}
int mn=0;
int mnla=0, mnfa=0;
for (int l : intres) {
int frst = 0;
int mnf = 0, mnsum = 0;
for (int i = 0; i < n; i++) {
if (v[i].x + up < l || v[i].x - down > l) continue;
if (frst == 0) mnf = v[i].y - 1;
mnsum = max(mnsum, v[i].y - frst - 1);
frst = v[i].y;
}
int mnl = c - frst;
mn = max(mn, mnsum);
mnla = max(mnla, mnl);
mnfa = max(mnfa, mnf);
}
if (mnla == c) continue;
mn = max(mn, mnla + mnfa);
if (mn > 2e9 - up - down) continue;
res = min(res, mn + down + up);
}
}
return res;
}
int run = 1;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
if (run == 1) {
int R, C, N;
cin >> R >> C >> N;
vector<int> X(N), Y(N);
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
}
int res = Time_To_Fool_The_Lab(R, C, N, X, Y);
cout << res << endl;
}
if (run == 2) {
vector<int> sizes = {0, 16, 16, 12, 20, 5 };
string name = "01-01";
for(int j=5;j<6;j++){
name[1] = '0' + j;
for (int i = 1; i < sizes[j]; i++) {
name[3] = '0' + i / 10; name[4] = '0' + i % 10;
ifstream fin(name + ".in"), fout(name + ".out");
int R, C, N;
fin >> R >> C >> N;
vector<int> X(N), Y(N);
for (int i = 0; i < N; i++) {
fin >> X[i] >> Y[i];
}
int nres, res = Time_To_Fool_The_Lab(R, C, N, X, Y);
fout >> nres;
if (nres != res) {
cout << "subtask " << j << "test" << i << endl;
cout << R << ' ' << C << endl << N << endl;
for (int i = 0; i < N; i++) {
cout << X[i] << ' ' << Y[i] << endl;
}
cout << res << ' ' << nres << endl;
break;
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |