Submission #00048
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | #include "bits/stdc++.h" // {{{ using namespace std; #define val const auto #define eb emplace_back #define emp emplace #define fi first #define se second #define X first #define Y second #define outl(x) cout << (x) << '\n' #define rep(i,n) for(int i=0; i < (int)(n); ++i) #define ALL(x) begin(x), end(x) #define TMPLT(T,U) template<class T, class U> #define ten(p) ((long long)(1e##p)) #define FILL(a,v) memset((a), (v), sizeof(a)) #define FAST() ios::sync_with_stdio(false), cin.tie(nullptr) #ifndef DEBUG #define debug(...) #define show(x) #define show2(x,y) #define LN() #endif typedef long long ll; typedef pair< int , int > pii; namespace ydk{ TMPLT(T,U) inline bool chmax(T &a, U b){ return b>a ? a=b,1 : 0;} TMPLT(T,U) inline bool chmin(T &a, U b){ return b<a ? a=b,1 : 0;} TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y) { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); } TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; } constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; // }}} constexpr int MX = ten(5) + 10; struct P { int hi, x, y; explicit P( int h, int x, int y): hi(h), x(x), y(y) {} bool operator < ( const P &p) const { return hi < p.hi; } bool operator > ( const P &p) const { return hi > p.hi; } }; void Xx_main_xX() { int H, W; static int mas[1005][1005]; static int goal[1005][1005]; const int RIDGE = 0; priority_queue< P, vector<P>, greater<P> > pq; cin >> H >> W; rep(i, H) { rep(j, W) { cin >> mas[i][j]; pq.emp(mas[i][j], j, i); } } static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1} ; int ans = 0; FILL(goal, -1); while (pq.size()) { const P tmp = pq.top(); pq.pop(); debug( "%d (%d, %d)\n" , tmp.hi, tmp.x+1, tmp.y+1); vector< int > buf; rep(i, 4) { int nx = tmp.x + dx[i]; int ny = tmp.y + dy[i]; if (nx < 0 || ny < 0 || nx >= W || ny >= H || goal[ny][nx] == -1) continue ; buf.eb(goal[ny][nx]); } sort(ALL(buf)); if (buf.empty()) { goal[tmp.y][tmp.x] = mas[tmp.y][tmp.x]; } else if (buf.front() == RIDGE || buf.front() != buf.back()) { goal[tmp.y][tmp.x] = RIDGE; ++ans; } else { goal[tmp.y][tmp.x] = buf.front(); } } #ifdef DEBUG rep(i, H) { rep(j, W) { if (goal[i][j] == RIDGE) { debug( " $ " ); } else { debug( " %2d " , goal[i][j]); } } debug( "\n" ); } #endif outl(ans); return ; } } // {{{ signed main(){cout << fixed << setprecision(9); ydk::Xx_main_xX(); return 0;} // }}} |
ステータス
項目 | データ |
---|---|
問題 | 0005 - 尾根 (Ridge) |
ユーザー名 | Arumakan_ei1727 |
投稿日時 | 2018-11-21 17:15:25 |
言語 | C++14 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 3029 Byte |
最大実行時間 | 504 ms |
最大メモリ使用量 | 20632 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | set1 | 20 / 20 | *t5*1.txt |
2 | set2 | 20 / 20 | *t5*2.txt |
3 | set3 | 20 / 20 | *t5*3.txt |
4 | set4 | 20 / 20 | *t5*4.txt |
5 | set5 | 20 / 20 | *t5*5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
2017-yo-t5-in1.txt | AC | 32 ms | 6620 KB |
1
|
||||
2017-yo-t5-in2.txt | AC | 504 ms | 20316 KB |
2
|
||||
2017-yo-t5-in3.txt | AC | 443 ms | 20268 KB |
3
|
||||
2017-yo-t5-in4.txt | AC | 453 ms | 20632 KB |
4
|
||||
2017-yo-t5-in5.txt | AC | 402 ms | 20264 KB |
5
|