답안 #938514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938514 2024-03-05T08:35:07 Z Wansur 전선 연결 (IOI17_wiring) C++14
0 / 100
1000 ms 2908 KB
#include <bits/stdc++.h>
//#include "slow.h"
#define f first
#define s second
#define ent '\n'

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

typedef long long ll;
using namespace std;
struct seg{
    int m1,m2,sum,cnt;
};

const string out[2]={"NO\n","YES\n"};

const ll dx[]={0,1,0,-1,-1,1,1,-1};
const ll dy[]={1,0,-1,0,-1,1,-1,1};
const int mod=998244353;
const int md=1e9+7;
const int mx=2e5+12;
const bool T=0;

ll dp[501][501];
ll c[501];
int n,m;

long long min_total_length(vector<int> a, vector<int> b){
    n=a.size(), m=b.size();
    if(n>m){
        swap(n,m);
        swap(a,b);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(int i=0;i<m;i++){
        for(int j=1;j<n;j++){
            if(abs(b[i]-a[j])<abs(b[i]-a[c[i]])){
                c[i]=j;
            }
        }
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++) {
            dp[i][j] = 1e18;
        }
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) {
            long long sum = 0;
            for (int k = j; k; k--) {
                long long val = sum + abs(b[k - 1] - a[i - 1]);
                dp[i][j] = min(dp[i][j], dp[i - 1][k - 1] + val);
                sum += abs(b[k - 1] - a[c[k - 1]]);
            }
        }
    }
    return dp[n][m];
}

/*
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '17422'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
3 Execution timed out 1058 ms 2908 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '17703', found: '19052'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '30'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '17422'
3 Halted 0 ms 0 KB -