# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957074 | mariaclara | Aliens (IOI16_aliens) | C++17 | 1 ms | 500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> trio;
typedef pair<ll,ll> pii;
const int MAXN = 2e5+5;
const int MOD = 1e9+7;
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define f first
#define s second
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pii> p;
for(int i = 0; i < n; i++)
p.pb({min(r[i],c[i])-1, max(r[i],c[i])});
sort(all(p), [](pii a, pii b){
if(a.f != b.f) return a.f < b.f;
return a.s > b.s;
});
vector<pii> square;
for(int i = 0; i < n; i++)
if(square.empty() or square.back().s < p[i].s) square.pb(p[i]);
ll ans = 0;
for(int i = 0; i < sz(square); i++) {
ans += (square[i].s - square[i].f)*(square[i].s - square[i].f);
if(i == 0) continue;
ans -= max(0LL, square[i-1].s - square[i].f)*max(0LL, square[i-1].s - square[i].f);
}
while(sz(square) > k) {
ll min_qtd = 1e12, ind = 0;
for(int i = 1; i < sz(square); i++) {
ll area = (square[i].s - square[i-1].f)*(square[i].s - square[i-1].f);
area -= (square[i].s - square[i].f)*(square[i].s - square[i].f);
area -= (square[i-1].s - square[i-1].f)*(square[i-1].s - square[i-1].f);
area += max(0LL, square[i-1].s - square[i].f)*max(0LL, square[i-1].s - square[i].f);
if(area < min_qtd) min_qtd = area, ind = i;
}
ans += min_qtd;
square[ind-1].s = square[ind].s;
square.erase(square.begin()+ind);
}
return ans;
}
Compilation message (stderr)
# | 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... |