結果

問題 No.2167 Fibonacci Knapsack
ユーザー tnakao0123
提出日時 2022-12-26 10:47:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 42,824 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-20 19:24:36
合計ジャッジ時間 4,395 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other RE * 21
権限があれば一括ダウンロードができます

ソースコード

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