Submission #618728


Source Code Expand

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)  
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef pair<long long, int> PLI;

struct edge {
  int to;
  int cost;
  int dst;
  long long penalty;
};

const long long INF = 1LL<<32;
int n, m, src, dst;
vector<edge> es[25252];
long long dist[25252];
long long dist2[25252];

bool check(long long x) {
  priority_queue<PLI, vector<PLI>, greater<PLI> > Q;
  fill(dist, dist + n, INF);
  dist[src] = 0;
  Q.push(MP(0, src));

  while (!Q.empty()) {
    long long cost = Q.top().first;
    int v = Q.top().second;
    Q.pop();

    if (cost > dist[v])
      continue;

    REP (i, es[v].size()) {
      edge &e = es[v][i];
      if (cost + e.penalty + dist2[e.dst] > x)
        continue;
      if (cost + e.cost < dist[e.to]) {
        dist[e.to] = cost + e.cost;
        Q.push(MP(dist[e.to], e.to));
      }
    }
  }
  return dist[dst] <= x;
}

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n >> m >> src >> dst;
    REP (i, m) {
      int l;
      cin >> l;

      vector<int> s(l), w(l);
      REP (i, l) cin >> s[i];
      REP (i, l-1) cin >> w[i];

      // forward
      long long penalty = accumulate(ALL(w), 0LL);
      REP (i, l-1) {
        es[s[i]].push_back({s[i+1], w[i], s.back(), penalty});
        penalty -= w[i];
      }

      // backword
      penalty = accumulate(ALL(w), 0LL);
      for (int i = l-1; i > 0; i--) {
        es[s[i]].push_back({s[i-1], w[i-1], s.front(), penalty});
        penalty -= w[i-1];
      }
    }

    // dijkstra to dst
    priority_queue<PLI, vector<PLI>, greater<PLI> > Q;
    fill(dist2, dist2+n, INF);
    dist2[dst] = 0;
    Q.push(MP(0 ,dst));

    while (!Q.empty()) {
      long long cost = Q.top().first;
      int v = Q.top().second;
      Q.pop();

      if (dist2[v] != cost)
        continue;

      REP (i, es[v].size()) {
        int w = es[v][i].to;
        int c = es[v][i].cost;

        if (cost + c < dist2[w]) {
          dist2[w] = cost + c;
          Q.push(MP(dist2[w], w));
        }
      }
    }

    // dijkstra from src with binary-search check
    long long hi = 1LL<<32;
    long long lo = -1;

    while (hi - lo > 1) {
      long long mi = (hi + lo) >> 1;
      if (check(mi))
        hi = mi;
      else
        lo = mi;
    }
    
    cout << hi << endl;
    
    return 0;
}

Submission Info

Submission Time
Task C - メンテナンス明け
User KenjiH
Language C++ (GCC 4.9.2)
Score 100
Code Size 2971 Byte
Status AC
Exec Time 334 ms
Memory 5756 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:85:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
         es[s[i]].push_back({s[i+1], w[i], s.back(), penalty});
                            ^
./Main.cpp:85:61: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
         es[s[i]].push_back({s[i+1], w[i], s.back(), penalty});
                                                             ^
./Main.cpp:92:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
         es[s[i]].push_back({s[i-1], w[i-1], s.front(), penalty});
                            ^
./Main.cpp:92:64: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
         es[s[i]].push_back({s[i-1], w[i-1], s.front(), penalty});
                                                                ^

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 52
AC × 6
Set Name Test Cases
Subtask1 small/00_sample00, small/00_sample01, small/00_sample02, small/10_small-0000, small/10_small-0001, small/10_small-0002, small/10_small-0003, small/10_small-0004, small/10_small-0005, small/10_small-0006, small/10_small-0007, small/10_small-0008, small/10_small-0009, small/10_small-0010, small/10_small-0011, small/10_small-0012, small/10_small-0013, small/10_small-0014, small/10_small-0015, small/10_small-0016, small/10_small-0017, small/10_small-0018, small/10_small-0019, small/30_max_small, small/40_simple_0000, small/40_simple_0001, small/40_simple_0002, small/40_simple_0003, small/40_simple_0004, small/40_simple_0005, small/40_simple_0006, small/40_simple_0007, small/40_simple_0008, small/40_simple_0009, small/40_simple_0010, small/40_simple_0011, small/40_simple_0012, small/40_simple_0013, small/40_simple_0014, small/40_simple_0015, small/40_simple_0016, small/40_simple_0017, small/40_simple_0018, small/40_simple_0019, small/90_dijkstra_killer_00, small/90_dijkstra_killer_01, small/91_tayama_killer_00, small/91_tayama_killer_01, small/91_tayama_killer_02, small/91_tayama_killer_03, small/91_tayama_killer_04, small/91_tayama_killer_05
Subtask2 large/20_large-00, large/20_large-01, large/20_large-02, large/20_large-03, large/20_large-04, large/31_max_large
Case Name Status Exec Time Memory
large/20_large-00 AC 299 ms 5756 KB
large/20_large-01 AC 295 ms 5748 KB
large/20_large-02 AC 334 ms 5740 KB
large/20_large-03 AC 307 ms 5688 KB
large/20_large-04 AC 324 ms 5700 KB
large/31_max_large AC 62 ms 3680 KB
small/00_sample00 AC 29 ms 1576 KB
small/00_sample01 AC 28 ms 1508 KB
small/00_sample02 AC 27 ms 1492 KB
small/10_small-0000 AC 30 ms 1676 KB
small/10_small-0001 AC 29 ms 1512 KB
small/10_small-0002 AC 29 ms 1676 KB
small/10_small-0003 AC 28 ms 1588 KB
small/10_small-0004 AC 29 ms 1572 KB
small/10_small-0005 AC 29 ms 1572 KB
small/10_small-0006 AC 30 ms 1672 KB
small/10_small-0007 AC 30 ms 1516 KB
small/10_small-0008 AC 30 ms 1684 KB
small/10_small-0009 AC 29 ms 1512 KB
small/10_small-0010 AC 32 ms 1592 KB
small/10_small-0011 AC 30 ms 1584 KB
small/10_small-0012 AC 30 ms 1692 KB
small/10_small-0013 AC 30 ms 1520 KB
small/10_small-0014 AC 31 ms 1584 KB
small/10_small-0015 AC 32 ms 1612 KB
small/10_small-0016 AC 32 ms 1680 KB
small/10_small-0017 AC 33 ms 1588 KB
small/10_small-0018 AC 32 ms 1684 KB
small/10_small-0019 AC 31 ms 1680 KB
small/30_max_small AC 32 ms 1552 KB
small/40_simple_0000 AC 29 ms 1468 KB
small/40_simple_0001 AC 29 ms 1684 KB
small/40_simple_0002 AC 31 ms 1560 KB
small/40_simple_0003 AC 28 ms 1556 KB
small/40_simple_0004 AC 30 ms 1684 KB
small/40_simple_0005 AC 27 ms 1684 KB
small/40_simple_0006 AC 29 ms 1592 KB
small/40_simple_0007 AC 28 ms 1688 KB
small/40_simple_0008 AC 27 ms 1680 KB
small/40_simple_0009 AC 29 ms 1680 KB
small/40_simple_0010 AC 29 ms 1576 KB
small/40_simple_0011 AC 29 ms 1580 KB
small/40_simple_0012 AC 29 ms 1684 KB
small/40_simple_0013 AC 28 ms 1684 KB
small/40_simple_0014 AC 27 ms 1588 KB
small/40_simple_0015 AC 29 ms 1504 KB
small/40_simple_0016 AC 30 ms 1588 KB
small/40_simple_0017 AC 28 ms 1508 KB
small/40_simple_0018 AC 27 ms 1508 KB
small/40_simple_0019 AC 27 ms 1456 KB
small/90_dijkstra_killer_00 AC 29 ms 1512 KB
small/90_dijkstra_killer_01 AC 27 ms 1584 KB
small/91_tayama_killer_00 AC 29 ms 1504 KB
small/91_tayama_killer_01 AC 28 ms 1480 KB
small/91_tayama_killer_02 AC 28 ms 1556 KB
small/91_tayama_killer_03 AC 28 ms 1500 KB
small/91_tayama_killer_04 AC 28 ms 1476 KB
small/91_tayama_killer_05 AC 28 ms 1508 KB