結果

問題 No.331 CodeRunnerでやれ
コンテスト
ユーザー h_noson
提出日時 2016-04-23 01:13:10
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 323 ms / 5,000 ms
コード長 2,363 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,506 ms
コンパイル使用メモリ 176,396 KB
実行使用メモリ 28,756 KB
平均クエリ数 1033.06
最終ジャッジ日時 2026-03-08 16:06:21
合計ジャッジ時間 7,565 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

int main() {
    int i, j, k, l, n, x, y, dir;
    int dxy[4] = {1,0,-1,0};
    int s[39][39] {};
    int d[39][39];
    x = y = 19;
    dir = 0;
    s[x][y] = 1;
    cin >> n;
    for (;;) {
        for (i = 0; i < 4 && n != 20151224; i++) {
            s[x+(n+1)*dxy[dir]][y+(n+1)*dxy[(dir+1)%4]] = 2;
            while (n--) s[x+(n+1)*dxy[dir]][y+(n+1)*dxy[(dir+1)%4]] = 1;
            cout << "L" << endl;
            cin >> n;
            dir = (dir + 1) % 4;
        }
        if (n == 20151224)
            break;
        bool found = false;
        REP (i,1,37) REP (j,1,37) if (!found && !s[i][j]) {
            rep (k,4) if (s[i+dxy[k]][j+dxy[(k+1)%4]] == 1) {
                queue<pair<int,int>> q;
                q.push(make_pair(i+dxy[k],j+dxy[(k+1)%4]));
                rep (l,39) fill(d[l],d[l]+39,INF);
                d[i+dxy[k]][j+dxy[(k+1)%4]] = 0;
                while (!q.empty()) {
                    int a, b;
                    tie(a,b) = q.front();
                    q.pop();
                    if (a == x && b == y)
                        break;
                    rep (l,4) {
                        int na, nb;
                        na = a+dxy[l];
                        nb = b+dxy[(l+1)%4];
                        if (s[na][nb] == 1 && d[a][b] + 1 < d[na][nb]) {
                            d[na][nb] = d[a][b] + 1;
                            q.push(make_pair(na,nb));
                        }
                    }
                }
                while (d[x][y] > 0) {
                    while (d[x][y] != d[x+dxy[dir]][y+dxy[(dir+1)%4]] + 1) {
                        cout << "L" << endl;
                        cin >> n;
                        dir = (dir + 1) % 4;
                    }
                    cout << "F" << endl;
                    cin >> n;
                    x += dxy[dir]; y+= dxy[(dir+1)%4];
                }
                found = true;
            }
        }
    }
    cin.ignore();
    string str;
    while (cout << "F" << endl, getline(cin,str), str != "Merry Christmas!");
    return 0;
}
0