結果

問題 No.1458 Segment Function
ユーザー 沙耶花沙耶花
提出日時 2021-03-31 21:28:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 4,650 ms
コンパイル使用メモリ 255,684 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 17:36:57
合計ジャッジ時間 5,484 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

void substruct(string &N){
	int n = N.size();
	for(int i=n-1;i>=0;i--){
		if(N[i]!='0'){
			N[i]--;
			break;
		}
		N[i] = '9';
	}
	while(N.size()>1&&N[0]=='0')N.erase(N.begin());
}

long long get(char c){
	vector<int> d = {6,2,5,5,4,5,6,4,7,6};
	if(isdigit(c))return d[c-'0'];
	if(c=='-')return 1;
	return 0;
}

long long get(string P){
	long long ret =0;
	rep(i,P.size()){
		ret += get(P[i]);
	}
	return ret;
}

long long get(long long P){
	return get(to_string(P));
}

int main(){
	
	string P,N;
	cin>>P>>N;
	
	if(N=="0"){
		cout<<P<<endl;
		return 0;
	}
	
	substruct(N);
	
	long long X = get(P);
	
	vector<int> A(1,X);
	
	while(true){
		if(N=="0"){
			cout<<X<<endl;
			return 0;
		}
		substruct(N);
		
		int t = get(X);
		bool f = true;
		rep(i,A.size()){
			if(t==A[i]){
				f=false;
				A.erase(A.begin(),A.begin()+i);
				break;
			}
		}
		if(!f)break;
		X = t;
		A.push_back(X);
	}
	
	int Mod = 0;
	rep(i,N.size()){
		Mod *= 10;
		Mod %= A.size();
		Mod += N[i]-'0';
		Mod %= A.size();
	}
	
	cout<<A[Mod]<<endl;
	
	
    return 0;
}
0