답안 #203619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203619 2020-02-21T15:46:04 Z galen_colin 웜뱃 (IOI13_wombats) C++14
55 / 100
20000 ms 218324 KB
#include <bits/stdc++.h>
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define io {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = lb; ele <= rb; ele++) { if (ele > lb) cout << " "; cout << a[ele]; } cout << '\n';}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
 
// template<typename A, typename B> ll max(A x, B y) {
//   return x > y ? x : y;
// }
// template<typename A, typename B> ll min(A x, B y) {
//   return x < y ? x : y;
// }
 
mt19937 rng(steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
 
// void init(int r, int c, int h[5000][200], int v[5000][200]);
 
// void changeH(int r, int c, int w);
 
// void changeV(int r, int c, int w);
 
// int escape(int c1, int c2);
 
// #define fail(s, x...) do { \
// 		fprintf(stderr, s "\n", ## x); \
// 		exit(1); \
// 	} while(0)
 
// static int H[5000][200];
// static int V[5000][200];
 
// int main() {
// 	int R, C, E, P, Q, W, V1, V2, event, i, j;
// 	int res;
 
// 	FILE *f = fopen("file.in", "r");
// 	if (!f)
// 		fail("Failed to open input file.");
 
// 	res = fscanf(f, "%d%d", &R, &C);
//     for (i = 0; i < R; ++i)
//         for (j = 0; j < C-1; ++j)
//             res = fscanf(f, "%d", &H[i][j]);
//     for (i = 0; i < R-1; ++i)
//         for (j = 0; j < C; ++j)
//             res = fscanf(f, "%d", &V[i][j]);
 
//     init(R, C, H, V);
 
// 	res = fscanf(f, "%d", &E);
// 	for (i = 0; i < E; i++) {
// 		res = fscanf(f, "%d", &event);
//         if (event == 1) {
//             res = fscanf(f, "%d%d%d", &P, &Q, &W);
//             changeH(P, Q, W);
//         } else if (event == 2) {
//             res = fscanf(f, "%d%d%d", &P, &Q, &W);
//             changeV(P, Q, W);
//         } else if (event == 3) {
//             res = fscanf(f, "%d%d", &V1, &V2);
//             printf("%d\n", escape(V1, V2));
//         } else
//             fail("Invalid event type.");
// 	}
 
// 	fclose(f);
// 	return 0;
// }
 
#include "wombats.h"

int n, m, k, q, Q, T, l, r, x, y, z;
int hh[5005][105];
int vv[5005][105];
const int dr[3] = {0, 1, 0};
const int dc[3] = {1, 0, -1};

inline bool valid(int r, int c) {
  return r >= 0 && r < n && c >= 0 && c < m;
}

struct dijkstra {
  int n;
  const int inf = 1.1e9;
  int dists[500005]; /* for a single run */
  bitset<500000> vis;
  
  void init(int s) {
    n = s;
  }
 
  using ptype = pair<int, int>;
  void run(int src) {
    for (int i = 0; i < n; i++) dists[i] = inf;
    vis = bitset<500000>(0);
 
    set<ptype> s;
    dists[src] = 0;
    s.insert(make_pair(0, src));
    while (!s.empty()) {
      ptype foc = *s.begin();
      s.erase(s.begin());
	  
	    if (vis[foc.s]) continue;
	    vis[foc.s] = 1;

      int rpos = foc.s / m;
      int cpos = foc.s % m;
	  
      dists[foc.s] = min(dists[foc.s], foc.f);

      if (valid(rpos, cpos - 1)) {
        int d = dists[foc.s] + hh[rpos][cpos - 1];
        int x = foc.s - 1;
        if (d < dists[x]) {
          auto it = s.find(make_pair(dists[x], x));
          if (it != s.end()) s.erase(it);
          dists[x] = d;
          s.insert(make_pair(d, x));
        }
      }

      if (valid(rpos, cpos + 1)) {
        int d = dists[foc.s] + hh[rpos][cpos];
        int x = foc.s + 1;
        if (d < dists[x]) {
          auto it = s.find(make_pair(dists[x], x));
          if (it != s.end()) s.erase(it);
          dists[x] = d;
          s.insert(make_pair(d, x));
        }
      }

      if (valid(rpos + 1, cpos)) {
        int d = dists[foc.s] + vv[rpos][cpos];
        int x = foc.s + m;
        if (d < dists[x]) {
          auto it = s.find(make_pair(dists[x], x));
          if (it != s.end()) s.erase(it);
          dists[x] = d;
          s.insert(make_pair(d, x));
        }
      }
    }
  }
};
 
// ll a[1000005];
// ll b[1000005];
// ll c[1000005];
string s, t;
ll ans = 0;
 
dijkstra dd[105];
bool ready[105];

void init_d(int i) {
  if (ready[i]) return;
  ready[i] = 1;

  dd[i].init(n * m);
  dd[i].run(i);
}

void recomp() {
  ms(ready, 0);
  f0r(i, m) dd[i].init(1);
}
 
void init(int r, int c, int h[5000][200], int v[5000][200]) {
  n = r;
  m = c;
  f0r(i, n) f0r(j, m - 1) {
    hh[i][j] = h[i][j];
  }
  f0r(i, n - 1) f0r(j, m) {
    vv[i][j] = v[i][j];
  }
  recomp();
  // f0r(i, m) cout << dd[i].dists << endl;
}
 
void changeH(int r, int c, int w) {
  hh[r][c] = w;
  recomp();
}
 
void changeV(int r, int c, int w) {
  vv[r][c] = w;
  recomp();
}
 
int escape(int c1, int c2) {
  if (!ready[c1]) init_d(c1);
  return dd[c1].dists[(n - 1) * m + c2];
}
 
// int main() {
//   io;
//   // freopen("case", "r", stdin);
//   // freopen("test.txt", "r", stdin);
//   // freopen("case", "w", stdout);
//   // freopen("file.in", "r", stdin);
 
//   // usaco("file");
 
  
// } 

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:81:1: warning: multi-line comment [-Wcomment]
 // #define fail(s, x...) do { \
 ^
wombats.cpp: In function 'void usaco(std::__cxx11::string)':
wombats.cpp:65:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((filename + ".in").c_str(), "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wombats.cpp:66:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((filename + ".out").c_str(), "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 13560 KB Output is correct
2 Correct 172 ms 13560 KB Output is correct
3 Correct 257 ms 16504 KB Output is correct
4 Correct 173 ms 13688 KB Output is correct
5 Correct 171 ms 13560 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 11 ms 7672 KB Output is correct
5 Correct 10 ms 7672 KB Output is correct
6 Correct 11 ms 7672 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 11 ms 7672 KB Output is correct
9 Correct 11 ms 7672 KB Output is correct
10 Correct 11 ms 7672 KB Output is correct
11 Correct 96 ms 10104 KB Output is correct
12 Correct 11 ms 7672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 10744 KB Output is correct
2 Correct 312 ms 10256 KB Output is correct
3 Correct 271 ms 10360 KB Output is correct
4 Correct 278 ms 10448 KB Output is correct
5 Correct 273 ms 10360 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 145 ms 7928 KB Output is correct
10 Correct 9 ms 7548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1087 ms 19704 KB Output is correct
2 Correct 1102 ms 19704 KB Output is correct
3 Correct 1153 ms 19828 KB Output is correct
4 Correct 1138 ms 21112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 10488 KB Output is correct
2 Correct 309 ms 10232 KB Output is correct
3 Correct 273 ms 10360 KB Output is correct
4 Correct 276 ms 10488 KB Output is correct
5 Correct 271 ms 10364 KB Output is correct
6 Correct 1068 ms 19704 KB Output is correct
7 Correct 1086 ms 19704 KB Output is correct
8 Correct 1088 ms 19700 KB Output is correct
9 Correct 1125 ms 21064 KB Output is correct
10 Correct 175 ms 13560 KB Output is correct
11 Correct 187 ms 13688 KB Output is correct
12 Correct 258 ms 16376 KB Output is correct
13 Correct 175 ms 13564 KB Output is correct
14 Correct 178 ms 13688 KB Output is correct
15 Correct 9 ms 7544 KB Output is correct
16 Correct 9 ms 7544 KB Output is correct
17 Correct 9 ms 7544 KB Output is correct
18 Correct 11 ms 7672 KB Output is correct
19 Correct 10 ms 7672 KB Output is correct
20 Correct 11 ms 7672 KB Output is correct
21 Correct 12 ms 7800 KB Output is correct
22 Correct 11 ms 7672 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7672 KB Output is correct
25 Correct 98 ms 10104 KB Output is correct
26 Correct 12 ms 7672 KB Output is correct
27 Correct 145 ms 8056 KB Output is correct
28 Execution timed out 20066 ms 218324 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 10488 KB Output is correct
2 Correct 326 ms 10220 KB Output is correct
3 Correct 279 ms 10360 KB Output is correct
4 Correct 275 ms 10492 KB Output is correct
5 Correct 273 ms 10360 KB Output is correct
6 Correct 1089 ms 19732 KB Output is correct
7 Correct 1111 ms 19832 KB Output is correct
8 Correct 1090 ms 19704 KB Output is correct
9 Correct 1133 ms 21388 KB Output is correct
10 Correct 175 ms 13560 KB Output is correct
11 Correct 171 ms 13560 KB Output is correct
12 Correct 262 ms 16376 KB Output is correct
13 Correct 176 ms 13688 KB Output is correct
14 Correct 172 ms 13688 KB Output is correct
15 Runtime error 312 ms 45176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Halted 0 ms 0 KB -