結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-16 05:54:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,525 bytes |
| コンパイル時間 | 400 ms |
| コンパイル使用メモリ | 48,128 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 23:04:45 |
| 合計ジャッジ時間 | 1,142 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 8 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d %d", &W, &H);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:60:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | scanf("%d", &map[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <queue>
#include <algorithm>
class counter_iterator{
private:
int count;
public:
counter_iterator() : count(0){}
counter_iterator(int n) : count(n){}
bool operator==(const counter_iterator& rhs) const{
return count == rhs.count;
}
bool operator!=(const counter_iterator& rhs) const{
return count != rhs.count;
}
int& operator*(){
return count;
}
counter_iterator& operator++(){
++count;
return *this;
}
};
class loop{
private:
int b, e;
public:
loop(int m) : b(0), e(m){}
loop(int n, int m) : b(n), e(m){}
counter_iterator begin() const{
return counter_iterator(b);
}
counter_iterator end() const{
return counter_iterator(e);
}
};
inline long long index(int t, int x, int y, int p1, int p2){
return x + 101ll * (y + 101 * (p1 + 10 * (p2 + 10 * t)));
}
inline bool isKadomatsu(int a, int b, int c){
if(a == b || b == c || c == a){return false;}
if(b != std::max({a, b, c}) && b != std::min({a, b, c})){return false;}
return true;
}
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int d[100][100][10][10];
int main(){
int W, H;
scanf("%d %d", &W, &H);
int map[100][100];
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
scanf("%d", &map[i][j]);
}
}
for(int i : loop(H)){
for(int j : loop(W)){
for(int k : loop(10)){
for(int l : loop(10)){
d[i][j][k][l] = 252521;
}
}
}
}
std::queue<long long> q;
q.push(index(0, 0, 0, 0, map[0][0]));
d[0][0][0][map[0][0]] = 0;
while(!q.empty()){
long long idx = q.front(); q.pop();
int x = idx%101,
y = idx/101%101,
p1 = idx/101/101%10,
p2 = idx/101/101/10%10,
t = idx / 101 / 101 / 10 / 10;
// printf("%d %d %d %d %d\n", x, y, p1, p2, t);
if(x == W-1 && y == H-1){printf("%d\n", t); return 0;}
if(t == 10000){break;}
for(int i=0;i<4;i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx < 0 || nx >= W || ny < 0 || ny >= H){
continue;
}
if((t < 1 || isKadomatsu(p1, p2, map[ny][nx])) && t+1 < d[nx][ny][p2][map[ny][nx]]){
q.push(index(t+1, nx, ny, p2, map[ny][nx]));
d[nx][ny][p2][map[ny][nx]] = t+1;
}
}
}
puts("-1");
}
tottoripaper