結果

問題 No.2167 Fibonacci Knapsack
ユーザー tnakao0123tnakao0123
提出日時 2022-12-26 10:47:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 42,080 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-13 02:55:42
合計ジャッジ時間 5,443 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3.cc: Dijkstra
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_L = 10000;

enum { PO, MO, PI, MI, PJ, MJ, PK, MK };

const int M = 8;
const int tms[M][M] = {
  //PO, MO, PI, MI, PJ, MJ, PK, MK
  { PO, MO, PI, MI, PJ, MJ, PK, MK }, // PO (+1)
  { MO, PO, MI, PI, MJ, PJ, MK, PK }, // MO (-1)
  { PI, MI, MO, PO, PK, MK, MJ, PJ }, // PI (+i)
  { MI, PI, PO, MO, MK, PK, PJ, MJ }, // MI (-i)
  { PJ, MJ, MK, PK, MO, PO, PI, MI }, // PJ (+j)
  { MJ, PJ, PK, MK, PO, MO, MI, PI }, // MJ (-j)
  { PK, MK, PJ, MJ, MI, PI, MO, PO }, // PK (+k)
  { MK, PK, MJ, PJ, PI, MI, PO, MO }, // MK (-k)
};

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_L + 4];
int cs[MAX_L], css[MAX_L * 8 + 1];

/* subroutines */

inline int c2i(char c) {
  return (c == 'i') ? PI : (c == 'j') ? PJ : (c == 'k') ? PK : -1;
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  for (int ti = 1; ti <= tn; ti++) {
    int l;
    ll x;
    scanf("%d%lld%s", &l, &x, s);
    ll lx = l * x;

    for (int i = 0; i < l; i++) cs[i] = c2i(s[i]);

    int l4 = l * 4, l8 = l * 8;
    css[0] = PO;
    for (int i = 0; i < l4; i++)
      css[i + 1] = tms[css[i]][cs[i % l]];
    for (int i = 1; i <= l4; i++) css[i + l4] = css[i];

    if (css[lx % l4] != MO) { printf("Case #%d: NO\n", ti); continue; }

    int ai = 0;
    for (; ai < l4 && css[ai] != PI; ai++);
    if (css[ai] != PI || ai >= lx) { printf("Case #%d: NO\n", ti); continue; }

    int bi = ai;
    for (; bi < l8 && css[bi] != PK; bi++);
    if (css[bi] != PK || bi >= lx) { printf("Case #%d: NO\n", ti); continue; }

    printf("Case #%d: YES\n", ti);
  }

  return 0;
}
0