結果

問題 No.432 占い(Easy)
ユーザー 🐬hec🐬hec
提出日時 2016-05-03 21:50:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 166,284 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 07:44:38
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

using namespace std;


char s[100010];

int main(void){
	int t,all=0;
	scanf("%d",&t);
	assert(1<= t&& t<=1000);
	
	rep(loop,t){
		scanf("%s",s);
		int n=strlen(s);
		assert(1<=n && n<=1000);
		all+=n;

		rep(i,n) assert(isdigit(s[i]));
		
		vector<int> seq[2];

		rep(i,n) seq[0].push_back(s[i]-'0');

		bool allzero=true;
		rep(i,n) if(seq[0][i]!=0) allzero=false;
		
		if(allzero){
			puts("0");
			continue;
		}

		int cur=0,nxt=1;
		while(seq[cur].size()>=2){
			seq[nxt].clear();
			int m=seq[cur].size();
			rep(i,m-1) seq[nxt].push_back((seq[cur][i]+seq[cur][i+1])%9);
			swap(cur,nxt);
		}

		int ans=seq[cur][0];
		if(ans==0) ans=9;
		printf("%d\n",ans);
	}
	assert(all<=1000);
	return 0;
}
0