AtCoder Regular Contest 025

Submission #1609772

Source codeソースコード

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1e15

struct edge{
    int to,cost;

    edge(){}
    edge(int x, int y){
        to = x;
        cost = y;
    }
};
 
VL dijkstra(vector<vector<edge> > &graph, int st = 0){
    int n = graph.size();
    VL d(n, INF);
    d[st] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(make_pair(0, st));
    while (!q.empty()){
        P a = q.top();
        q.pop();
        int now = a.second;
        if(d[now] < a.first) continue;
        REP(i,graph[now].size()){
            edge e = graph[now][i];
            int next = e.to;
            if (d[next] > d[now] + e.cost){
                d[next] = d[now] + e.cost;
                q.push(make_pair(d[next], next));
            }
        }
    }
    return d;
}

int main(){
    int n, m, r, t;
    cin >> n >> m >> r >> t;

    vector<vector<edge> > e(n);
    REP(i,m){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--;
        b--;
        e[a].push_back(edge(b,c));
        e[b].push_back(edge(a,c));
    }

    ll ans = 0;
    REP(s,n){
        VL d = dijkstra(e, s);
        sort(ALL(d));
        d.erase(d.begin());
        reverse(ALL(d));
        // cout << s << endl;
        // for (ll p : d) cout << p << " ";
        // cout << endl;
        int j = 0;
        REP(i,n-1){
            while (j < n-1 && r * d[i] < t * d[j]) j++;
            if (j <= i) ans += j;
            else ans += j - 1;
        }
    }

    cout << ans << endl;

    return 0;
}




Submission

Task問題 C - ウサギとカメ
User nameユーザ名 TangentDay
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 2138 Byte
File nameファイル名
Exec time実行時間 1001 ms
Memory usageメモリ使用量 384 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:70:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample-01.txt,subtask0_sample-02.txt
All 100 / 100 subtask0_sample-01.txt,subtask0_sample-02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample-01.txt AC 1 ms 256 KB
subtask0_sample-02.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 6 ms 256 KB
subtask1_06.txt AC 8 ms 256 KB
subtask1_07.txt AC 28 ms 384 KB
subtask1_08.txt AC 35 ms 256 KB
subtask1_09.txt AC 301 ms 384 KB
subtask1_10.txt AC 281 ms 384 KB
subtask1_11.txt AC 126 ms 384 KB
subtask1_12.txt AC 899 ms 384 KB
subtask1_13.txt AC 898 ms 384 KB
subtask1_14.txt AC 997 ms 384 KB
subtask1_15.txt AC 681 ms 384 KB
subtask1_16.txt AC 1001 ms 384 KB