답안 #383720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383720 2021-03-30T17:06:24 Z Valera_Grinenko Tracks in the Snow (BOI13_tracks) C++17
100 / 100
785 ms 131132 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 4000;
char s[N][N];
int d[N][N];
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int h, w;

  cin >> h >> w;

  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
      cin >> s[i][j];

  deque<pair<int, int> > q;

  q.push_front(mp(0, 0));

  d[0][0] = 1;

  int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};

  int ans = 1;

  while(!q.empty()) {
    auto cv = q.front(); q.pop_front();
    int x = cv.fi, y = cv.se;
    ans = max(ans, d[x][y]);
    for(int mv = 0; mv < 4; mv++) {
      int cx = x + dx[mv], cy = y + dy[mv];
      if(cx >= 0 && cx < h && cy >= 0 && cy < w && d[cx][cy] == 0 && s[cx][cy] != '.') {
        d[cx][cy] = d[x][y] + (s[cx][cy] != s[x][y]);
        if(d[cx][cy] > d[x][y]) q.push_back(mp(cx, cy));
        else q.push_front(mp(cx, cy));
      }
    }
  }

  cout << ans;

  return 0;
}
/*

*/

Compilation message

tracks.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5484 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 10 ms 5228 KB Output is correct
5 Correct 5 ms 2924 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 760 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 5 ms 2540 KB Output is correct
11 Correct 4 ms 2156 KB Output is correct
12 Correct 9 ms 3180 KB Output is correct
13 Correct 7 ms 2932 KB Output is correct
14 Correct 5 ms 2924 KB Output is correct
15 Correct 15 ms 5356 KB Output is correct
16 Correct 17 ms 5504 KB Output is correct
17 Correct 13 ms 5228 KB Output is correct
18 Correct 11 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 30700 KB Output is correct
2 Correct 64 ms 15008 KB Output is correct
3 Correct 385 ms 73196 KB Output is correct
4 Correct 115 ms 32736 KB Output is correct
5 Correct 243 ms 53272 KB Output is correct
6 Correct 778 ms 107692 KB Output is correct
7 Correct 20 ms 32108 KB Output is correct
8 Correct 19 ms 30700 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 20 ms 31596 KB Output is correct
12 Correct 2 ms 1644 KB Output is correct
13 Correct 63 ms 15084 KB Output is correct
14 Correct 37 ms 10604 KB Output is correct
15 Correct 34 ms 13164 KB Output is correct
16 Correct 27 ms 5740 KB Output is correct
17 Correct 158 ms 28780 KB Output is correct
18 Correct 130 ms 35692 KB Output is correct
19 Correct 115 ms 32748 KB Output is correct
20 Correct 91 ms 25532 KB Output is correct
21 Correct 226 ms 52588 KB Output is correct
22 Correct 242 ms 53228 KB Output is correct
23 Correct 308 ms 43756 KB Output is correct
24 Correct 231 ms 50028 KB Output is correct
25 Correct 566 ms 94188 KB Output is correct
26 Correct 507 ms 131132 KB Output is correct
27 Correct 662 ms 111980 KB Output is correct
28 Correct 784 ms 107528 KB Output is correct
29 Correct 785 ms 107676 KB Output is correct
30 Correct 720 ms 107120 KB Output is correct
31 Correct 607 ms 73452 KB Output is correct
32 Correct 607 ms 109036 KB Output is correct