結果

問題 No.2193 メガの下1桁
ユーザー Aging1986Aging1986
提出日時 2023-01-13 23:04:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,579 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 203,724 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-26 04:48:15
合計ジャッジ時間 3,635 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vd> vvd;
#define yn(ans) printf("%s\n", (ans)?"Yes":"No");
#define YN(ans) printf("%s\n", (ans)?"YES":"NO");
template<class T> bool chmax(T &a, T b) {
	if (a >= b) return false;
	a = b; return true;
}
template<class T> bool chmin(T &a, T b) {
	if (a <= b) return false;
	a = b; return true;
}
#define FOR(i, s, e, t) for ((i) = (s); (i) < (e); (i) += (t)) 
#define REP(i, e) for (int i = 0; i < (e); ++i) 
#define REP1(i, s, e) for (int i = (s); i < (e); ++i)
#define RREP(i, e) for (int i = (e); i >= 0; --i)
#define RREP1(i, e, s) for (int i = (e); i >= (s); --i)
#define all(v) v.begin(), v.end()
#define pb push_back
#define qb pop_back
#define pf push_front
#define qf pop_front
#define maxe max_element
#define mine min_element
ll inf = 1e18;
#define DEBUG printf("%d\n", __LINE__); fflush(stdout);
template<class T> void print(vector<T> &v, bool withSize) {
	if (withSize) cout << v.size() << endl;
	REP(i, v.size()) cout << v[i] << " "; 
	cout << "\n";
}
mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

int __FAST_IO__ = []() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);
	return 0;
}();

int main() {
    ll M, D, N; int B;
    cin >> M >> D >> N >> B;
    vvi p(B);
    vi sc(B), tc(B);
    REP(i, B) {
    	vi used(B, -1);
    	int c = 1, id = 0;
    	while (used[c] == -1) {
    		used[c] = id;
    		p[i].pb(c);
    		int next = c * i % B;
			id++;
			c = next;
    	}
    	sc[i] = used[c], tc[i] = id - used[c];
    //	cout << i << " " << sc[i] << " " << tc[i] << endl;
    //	print(p[i], false);
    	
    }
    
    int x = D % B;
    
    vi used(B, -1);
    int ss = -1, tt = -1;
    int ans = -1;
    REP(i, N) {
    	if (used[x] != -1) {
    		ss = used[x], tt = i - ss;
    		REP(j, B) {
    			if (used[j] - ss == (N - ss) % tt) {
    				ans = j;
    				break;
    			}
    		}
    		break;
    	} else {
    		used[x] = i;
    		x = (x + M) % B;
    		if (M < sc[x]) x = p[x][M];
    		else {
    			x = p[x][(M - sc[x]) % tc[x] + sc[x]];
    		}
    	}
    	
    	//printf("after %d %d\n", i, x);
    }
    
    if (ans == -1) ans = x;
    if (ans == 10) printf("A\n");
    else printf("%d\n", ans);
    return 0;
}
0