답안 #823449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823449 2023-08-12T14:20:04 Z merlin Aliens (IOI16_aliens) C++14
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
#include "aliens.h"
using namespace std;
#define ll long long
#define f first
#define s second

void setIO(string name="") {
	cin.tie(0)->sync_with_stdio(0);
	if (!name.empty()) {
		freopen((name+".in").c_str(), "r", stdin);
		freopen((name+".out").c_str(), "w", stdout);
	}
}

void set_min(ll &a,ll b){
    a = min(a,b);
}

/*
ll take_photos(int n,int m,int K,vector<int> r,vector<int> c){
    vector<int> poradie(n);
    iota(poradie.begin(),poradie.end(),0);
    sort(poradie.begin(),poradie.end(),[&r] (int a,int b){return r[a] < r[b];});
    ll DP[n+1][K+1];
    for(int i = 0;i<n;i++)for(int k = 0;k<K+1;k++){
        DP[i][k] = 1e18;
    }
    for(int i = 0;i<=K;i++) DP[0][i] = 0;
    for(int i = 1;i<=n;i++)for(int k = 0;k < K;k++){
        for(int j = 0;j<i;j++){
            set_min(DP[i][k],DP[j][k+1] + pow((ll) r[poradie[i-1]] - r[poradie[j]] + 1,2));
        }
        //cerr<<i<<" "<<k<<" "<<DP[i][k]<<endl;
    }
    ll ans = 1e18;
    for(int i = 0;i<=K;i++) ans = min(ans,DP[n][i]);
    return ans;
}
*/
ll DP[510][510];

ll take_photos(int n,int m,int K,vector<int> r,vector<int> c){
    set<pair<ll,ll>> a;
    for(int i = 0;i<n;i++){
        a.insert({r[i],c[i]});
        assert(r[i] == c[i]);
    }
    vector<ll> R;
    for(auto i : a) R.push_back(i.f);
    int N = a.size();
    for(int i = 0;i<N+1;i++)for(int j = 0;j<K+1;j++)DP[i][j] = 1e18;
    for(int i = 0;i<=K;i++) DP[0][i] = 0;
    for(int i = 1;i<=n;i++)for(int k = 1;k <= K;k++){
        for(int j = 0;j<i;j++){
            set_min(DP[i][k],DP[j][k-1] + (R[i-1] - R[j] + 1)*(R[i-1] - R[j] + 1));
        }
        //cerr<<i<<" "<<k<<" "<<DP[i][k]<<endl;
    }
    ll ans = 1e18;
    for(int i = 0;i<=K;i++) ans = min(ans,DP[n][i]);
    return ans;
}

Compilation message

aliens.cpp: In function 'void setIO(std::string)':
aliens.cpp:11:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   freopen((name+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aliens.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   freopen((name+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 1
2 Correct 0 ms 212 KB Correct answer: answer = 4
3 Incorrect 1 ms 212 KB Wrong answer: output = 0, expected = 1
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -