Submission #1766621


Source Code Expand

#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm( int m, int n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int dp[4001][4001];

signed main(){
    int n; cin>>n;
    vector<int>c(n);
    pii comp; cin>>comp.first>>comp.second;
    vector<pii>val;
    rep(i,4001)rep(j,4001)dp[i][j]=INF;
    rep(i,n){
        pii temp; cin>>temp.first>>temp.second;
        val.push_back(temp);
        cin>>c[i];
    }
    rep(i,n){
        cmin(dp[val[i].first][val[i].second],c[i]);
        rep(j,4001){
            rep(k,4001){
                if(dp[j][k]==INF)continue;
                if(j==val[i].first&&k==val[i].second)continue;
                pii ni=pii(gcd(j,val[i].first),gcd(k,val[i].second));
                cmin(dp[ni.first][ni.second],dp[j][k]+c[i]);
            }
        }
    }
    int ans=INF;
    if(dp[comp.first][comp.second]==INF)return puts("-1")*0;
    cout<<(dp[comp.first][comp.second])<<endl;
}

Submission Info

Submission Time
Task D - Mixing Experiment
User yebityon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1961 Byte
Status WA
Exec Time 858 ms
Memory 62720 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 2
AC × 7
WA × 13
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt
Case Name Status Exec Time Memory
sample_01.txt AC 83 ms 62720 KB
sample_02.txt AC 41 ms 62720 KB
subtask_1_01.txt AC 125 ms 62720 KB
subtask_1_02.txt AC 62 ms 62720 KB
subtask_1_03.txt AC 125 ms 62720 KB
subtask_1_04.txt AC 229 ms 62720 KB
subtask_1_05.txt WA 292 ms 62720 KB
subtask_1_06.txt WA 397 ms 62720 KB
subtask_1_07.txt WA 460 ms 62720 KB
subtask_1_08.txt WA 502 ms 62720 KB
subtask_1_09.txt WA 606 ms 62720 KB
subtask_1_10.txt WA 711 ms 62720 KB
subtask_1_11.txt WA 816 ms 62720 KB
subtask_1_12.txt WA 858 ms 62720 KB
subtask_1_13.txt WA 858 ms 62720 KB
subtask_1_14.txt WA 858 ms 62720 KB
subtask_1_15.txt WA 858 ms 62720 KB
subtask_1_16.txt WA 858 ms 62720 KB
subtask_1_17.txt WA 858 ms 62720 KB
subtask_1_18.txt AC 858 ms 62720 KB