結果

問題 No.1584 Stones around Circle Pond
ユーザー milanis48663220milanis48663220
提出日時 2021-07-02 23:12:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,500 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-11 23:39:20
合計ジャッジ時間 3,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 WA -
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <numeric>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

const ll INF = 1e+15;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; ll l; cin >> n >> l;
    vector<ll> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];
    vector<ll> b(2*n);
    for(int i = 0; i < 2*n; i++) cin >> b[i];
    ll b_sum = accumulate(b.begin(), b.end(), 0ll);
    for(int i = 0; i < n; i++){
        if((b[i]+b[i+n])*n != b_sum){
            cout << "No" << endl;
            return 0;
        }
    }
    ll D = b_sum/(l*n);
    vector<int> x(n-1);
    vector<int> y(n-1);
    for(int i = 0; i < n-1; i++){
        if((b[i]-b[i+1])%(d[i+1]-d[i]) != 0){
            cout << "No" << endl;
            return 0;
        }
        x[i] = (b[i]-b[i+1])/(d[i+1]-d[i]);
        if(D-x[i] < 0 || (D-x[i])%2 != 0){
            cout << "No" << endl;
            return 0;
        }
        y[i] = (D-x[i])/2;
    }
    vector<vector<edge>> g(2*n);
    for(int i = 0; i < n-1; i++){
        g[i].push_back(edge{i+n, y[i]});
    }
    for(int i = 0; i < 2*n-1; i++){
        g[i+1].push_back(edge{i, 0});
    }
    auto dist = dijkstra(0, g);
    for(int i = 0; i < n-1; i++){
        if(dist[i+n]-dist[i] != y[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
0