Submission #135443

# Submission time Handle Problem Language Result Execution time Memory
135443 2019-07-24T05:46:27 Z Talant Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 92536 KB
#include "wombats.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

#define sc second
#define fr first
#define mk make_pair
#define pb push_back

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e9 + 7);

int n,m;
int d[3][N];
int sum;

vector <pair<int,int> > g[N];
void djikstra(int v,int o) {
      for (int i = 1; i <= n * m; i ++) d[o][i] = inf;
      d[o][v] = 0;
      priority_queue<pair<int,int> > q;
      q.push(mk(0,v));

      while (!q.empty()) {
            int v = q.top().sc,cur = -q.top().fr;
            q.pop();
            if (cur > d[o][v]) continue;
            for (auto to : g[v]) {
                  if (d[o][v] + to.sc < d[o][to.fr]) {
                        d[o][to.fr] = d[o][v] + to.sc;
                        q.push(mk(-d[o][to.fr],to.fr));
                  }
            }
      }
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
      n = R,m = C;

      for (int i = 1; i <= n; i ++) {
            for (int j = 1; j < m; j ++) {
                  int cur = (i - 1) * m + j;
                  g[cur].pb(mk(cur + 1,H[i - 1][j - 1]));
                  g[cur + 1].pb(mk(cur,H[i - 1][j - 1]));
            }
      }
      for (int i = 1; i < n; i ++) {
            for (int j = 1; j <= m; j ++) {
                  int cur = (i - 1) * m + j;
                  sum += V[i - 1][j - 1];
                  g[cur].pb(mk(cur + m,V[i - 1][j - 1]));
            }
      }
      if (m == 2) {
            djikstra(1,1);
            djikstra(2,2);
      }
}

void changeH(int P, int Q, int W) {
      P ++,Q ++;
      int cur = (P - 1) * m + Q;
      for (int i = 0; i < g[cur].size(); i ++) {
            if (g[cur][i].fr == cur + 1) g[cur][i].sc = W;
      }
      for (int i = 0; i < g[cur + 1].size(); i ++) {
            if (g[cur + 1][i].fr == cur) g[cur + 1][i].sc = W;
      }
      if (m == 2) {
            djikstra(1,1);
            djikstra(2,2);
      }
}

void changeV(int P, int Q, int W) {
      P ++,Q ++;
      int cur = (P - 1) * m + Q;
      sum += W;
      for (int i = 0; i < g[cur].size(); i ++) {
            if (g[cur][i].fr == cur + m) sum -= g[cur][i].sc,g[cur][i].sc = W;
      }
      if (m == 2) {
            djikstra(1,1);
            djikstra(2,2);
      }
}
int escape(int V1, int V2) {
      if (m == 1) return sum;
      if (m == 2) {
            return d[++V1][(n - 1) * m + V2 + 1];
      }
      V1 ++,V2 ++;


      djikstra(V1,1);
      return d[1][(n - 1) * m + V2];
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
wombats.cpp: In function 'void changeH(int, int, int)':
wombats.cpp:65:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < g[cur].size(); i ++) {
                       ~~^~~~~~~~~~~~~~~
wombats.cpp:68:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < g[cur + 1].size(); i ++) {
                       ~~^~~~~~~~~~~~~~~~~~~
wombats.cpp: In function 'void changeV(int, int, int)':
wombats.cpp:81:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < g[cur].size(); i ++) {
                       ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 27896 KB Output is correct
2 Correct 28 ms 27896 KB Output is correct
3 Correct 99 ms 29560 KB Output is correct
4 Correct 28 ms 27896 KB Output is correct
5 Correct 28 ms 28024 KB Output is correct
6 Correct 23 ms 23772 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 43 ms 23932 KB Output is correct
5 Correct 32 ms 23928 KB Output is correct
6 Correct 33 ms 23928 KB Output is correct
7 Correct 50 ms 23856 KB Output is correct
8 Correct 38 ms 23928 KB Output is correct
9 Correct 41 ms 23928 KB Output is correct
10 Correct 39 ms 23940 KB Output is correct
11 Correct 8928 ms 25040 KB Output is correct
12 Correct 49 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 24564 KB Output is correct
2 Correct 261 ms 24656 KB Output is correct
3 Correct 184 ms 24500 KB Output is correct
4 Correct 185 ms 24588 KB Output is correct
5 Correct 185 ms 24568 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 22 ms 23764 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 265 ms 24616 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 492 ms 32100 KB Output is correct
2 Correct 1287 ms 32144 KB Output is correct
3 Correct 492 ms 32092 KB Output is correct
4 Correct 530 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 24580 KB Output is correct
2 Correct 264 ms 24568 KB Output is correct
3 Correct 186 ms 24632 KB Output is correct
4 Correct 186 ms 24696 KB Output is correct
5 Correct 201 ms 24568 KB Output is correct
6 Correct 491 ms 32252 KB Output is correct
7 Correct 1283 ms 32120 KB Output is correct
8 Correct 497 ms 32376 KB Output is correct
9 Correct 535 ms 33168 KB Output is correct
10 Correct 27 ms 27896 KB Output is correct
11 Correct 29 ms 27896 KB Output is correct
12 Correct 98 ms 30712 KB Output is correct
13 Correct 29 ms 28028 KB Output is correct
14 Correct 28 ms 27896 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 44 ms 23928 KB Output is correct
19 Correct 33 ms 23928 KB Output is correct
20 Correct 35 ms 24056 KB Output is correct
21 Correct 50 ms 23928 KB Output is correct
22 Correct 48 ms 23932 KB Output is correct
23 Correct 41 ms 23928 KB Output is correct
24 Correct 40 ms 23928 KB Output is correct
25 Correct 8909 ms 26576 KB Output is correct
26 Correct 49 ms 23928 KB Output is correct
27 Correct 266 ms 24696 KB Output is correct
28 Execution timed out 20082 ms 60920 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 186 ms 24696 KB Output is correct
2 Correct 261 ms 24652 KB Output is correct
3 Correct 185 ms 24568 KB Output is correct
4 Correct 184 ms 24696 KB Output is correct
5 Correct 185 ms 24568 KB Output is correct
6 Correct 496 ms 32124 KB Output is correct
7 Correct 1287 ms 32224 KB Output is correct
8 Correct 502 ms 32228 KB Output is correct
9 Correct 534 ms 33068 KB Output is correct
10 Correct 28 ms 27896 KB Output is correct
11 Correct 28 ms 28024 KB Output is correct
12 Correct 105 ms 30764 KB Output is correct
13 Correct 28 ms 28024 KB Output is correct
14 Correct 28 ms 27896 KB Output is correct
15 Correct 1491 ms 92536 KB Output is correct
16 Execution timed out 20053 ms 90616 KB Time limit exceeded
17 Halted 0 ms 0 KB -