結果

問題 No.613 Solitude by the window
ユーザー QCFiumQCFium
提出日時 2019-09-29 12:12:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 946 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 175,840 KB
実行使用メモリ 269,660 KB
最終ジャッジ日時 2024-04-14 07:13:26
合計ジャッジ時間 9,372 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,888 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 76 ms
112,304 KB
testcase_04 TLE -
testcase_05 AC 46 ms
96,248 KB
testcase_06 AC 56 ms
88,624 KB
testcase_07 AC 652 ms
142,536 KB
testcase_08 AC 540 ms
154,448 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:41: warning: 'index' may be used uninitialized [-Wmaybe-uninitialized]
   42 |                 int left = (n - i) % (i - index);
      |                                      ~~~^~~~~~~~
main.cpp:40:21: note: 'index' was declared here
   40 |                 int index;
      |                     ^~~~~

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int64_t n = rll();
	int m = ri();
	if (m == 2) {
		std::cout << 0 << std::endl;
		return 0;
	}
	int cur = 2;
	std::map<int, int> rep = {
		{1000000007, 250000001},
		{1099999997, 61111110},
	};
	if (rep.count(m)) {
		n %= rep[m];
		for (int i = 0; i < n; i++) cur = (int64_t) cur * (cur + 4) % m;
	} else {
		std::vector<bool> used(m);
		std::vector<int> list;
		list.reserve(50000000);
		int i = 0;
		for (; i < n; i++) {
			if (used[cur]) break;
			used[cur] = true;
			list.push_back(cur);
			cur = (int64_t) cur * (cur + 4) % m;
		}
		int index;
		for (int i = 0; i < (int) list.size(); i++) if (list[i] == cur) { index = i; break; }
		int left = (n - i) % (i - index);
		for (int i = 0; i < left; i++) cur = (int64_t) cur * (cur + 4) % m;
	}
	std::cout << cur << std::endl;
	return 0;
}
0