結果

問題 No.613 Solitude by the window
ユーザー zimphazimpha
提出日時 2017-12-13 00:12:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 54,776 KB
実行使用メモリ 137,052 KB
最終ジャッジ日時 2023-08-20 23:58:28
合計ジャッジ時間 17,958 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 WA -
testcase_11 AC 271 ms
4,380 KB
testcase_12 AC 650 ms
4,380 KB
testcase_13 AC 1,254 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:44:16: 警告: ‘extra’ may be used uninitialized [-Wmaybe-uninitialized]
   44 |   n %= (target - extra);
      |        ~~~~~~~~^~~~~~~~
main.cpp:21:20: 備考: ‘extra’ はここで定義されています
   21 |   int64 x = 2 % m, extra, target = -1, end;
      |                    ^~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <map>

using int64 = long long;

int main() {
  int64 n, m;
  scanf("%lld%lld", &n, &m);
  if (m == 1000000007) {
    n %= 250000001;
    int64 x = 2;
    for (int i = 0; i < n; ++i) {
      x = (x * x + 4 * x) % m;
    }
    printf("%lld\n", x);
    return 0;
  }
  std::vector<bool> mark(m);
  mark[2 % m] = 1;
  int64 x = 2 % m, extra, target = -1, end;
  for (int i = 1; i <= n; ++i) {
    x = (x * x + 4 * x) % m;
    if (mark[x]) {
      target = x;
      end = i;
      break;
    }
    mark[x] = 1;
  }
  if (target == -1) {
    printf("%lld\n", x);
    return 0;
  }
  x = 2 % m;
  for (int i = 0; i <= n; ++i) {
    if (x == target) {
      extra = i;
      break;
    }
    x = (x * x + 4 * x) % m;
  }
  n -= extra;
  n %= (target - extra);
  if (n == 0) n += (target - extra);
  for (int i = 0; i < n; ++i) {
    x = (x * x + x * 4) % m;
  }
  printf("%lld\n", x);
  return 0;
}
0