답안 #760649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760649 2023-06-18T04:59:39 Z AryanReddy Aliens (IOI16_aliens) C++14
0 / 100
1 ms 468 KB
#undef local
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fori(i,n) for(int i=0;i<n;i++)
#define ford(i,n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define ll long long int
//#define mod 998244353
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define printVector(v) fori(;,v.size()) {cout << v[i] << " ";} cout << "\n";
#pragma GCC optimize("O3")
std::mt19937 rng((unsigned int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
ll getAns(vector<pll> a,ll k){
    int n = a.size();
    sort(all(a),[&](pll x,pll y){
        return mp(x.fi,-x.se) < mp(y.fi,-y.se);
    });
    int ptr = a[0].se;
    vector<pll> b = {a[0]};
    for(int i= 1;i < n;i++){
        if(a[i].se <= ptr){
            continue;
        }
        b.push_back(a[i]);
        ptr = a[i].se;
    }
    a = b;
    n = a.size();
    vector<vector<ll> > dp(n+1,vector<ll> (k+1,1e18));
    fori(i,k+1) dp[0][i] = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= k;j++){
            dp[i][j] = dp[i][j-1];
            vector<ll>  vals;
            for(int t = i;t >= 1;t--){
                ll d = a[i-1].se - a[t-1].fi + 1;
                d *= d;
                if(t >= 2 && a[t-1].fi <= a[t-2].se){
                    ll s = a[t-2].se - a[t-1].fi + 1;
                    s *= s;
                    d -= s;
                }
                dp[i][j]  = min(dp[i][j],dp[t-1][j-1] + d);
                vals.pb(dp[t-1][j-1] + d);
            }
            int sz = vals.size();
            for(int i = 0;i < sz-2;i++){
                assert(vals[i+1] - vals[i] >= vals[i+2] - vals[i+1]);
            }
        }
    }
    return dp[n][k];
}

long long take_photos(int n, int m, int k, vector<int> r, vector<int> c){
    vector<pll> a;
    for(int i = 0;i < n;i++){
        int x = r[i];
        int y = c[i];
        a.pb(mp(min(x,y),max(x,y)));
    }
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    ll ans = getAns(a,k);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 4
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 4
4 Correct 0 ms 300 KB Correct answer: answer = 12
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 1
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 1
4 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 4
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 4
4 Correct 0 ms 300 KB Correct answer: answer = 12
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 4
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 4
4 Correct 0 ms 300 KB Correct answer: answer = 12
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 4
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 4
4 Correct 0 ms 300 KB Correct answer: answer = 12
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Correct answer: answer = 4
2 Correct 1 ms 212 KB Correct answer: answer = 4
3 Correct 1 ms 212 KB Correct answer: answer = 4
4 Correct 0 ms 300 KB Correct answer: answer = 12
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -