結果

問題 No.2228 Creeping Ghost
ユーザー lddlinanlddlinan
提出日時 2023-03-03 14:46:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 85,612 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 00:59:02
合計ジャッジ時間 1,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



char ob[1000004];
void assert(int *p) { *p=0; }
int main() {
    int n, i, j, k;
    const char* p[] = {
        "RLRD",
        "DUDL",
        "LRLU",
        "UDUR",
    };
    scanf("%d", &n);
    if (n<4) {
        for (i=0; i<n; i++) ob[i]='D';
    } else {
        ob[0]='R'; ob[1]='L'; ob[2]='R'; ob[3]='D';
        for (i=4; i<n; ) {
            for (k=0; k<4&&i<n; k++) {
                for (j=0; j<4&&i<n; j++) {
                    ob[i++]=p[k][j];
                }
            }
        }
    }
    ob[n]=0;
    // check
    int px=0, py=0, cx=0, cy=0, x=-1, y=-1;
    for (i=0; i<n; i++) {
        if (ob[i]=='R') cy++;
        else if (ob[i]=='L') cy--;
        else if (ob[i]=='U') cx--;
        else cx++;
        if (cx<0||cx>4||cy<0||cy>4) assert(0);
        if ((i%4)==3) {
            x=px; y=py;
            px=cx; py=cy;
        }
        if (cx==x||cy==y) assert(0);
    }
    printf("%s\n", ob);
    return 0;
}
0