結果

問題 No.528 10^9と10^9+7と回文
ユーザー kuuso1kuuso1
提出日時 2017-06-09 23:49:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,984 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 111,636 KB
実行使用メモリ 25,248 KB
最終ジャッジ日時 2023-10-24 03:10:24
合計ジャッジ時間 4,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
23,884 KB
testcase_01 AC 23 ms
23,884 KB
testcase_02 AC 24 ms
23,952 KB
testcase_03 AC 23 ms
23,952 KB
testcase_04 AC 24 ms
23,904 KB
testcase_05 AC 23 ms
23,904 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 33 ms
25,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Console.WriteLine(calc((long) 1e9));
		Console.WriteLine(calc((long) 1e9 + 7));
		
	}
	
	long calc(long mod){
		
		int N = S.Length;
		if(N == 1){ return (long) (S[0] - '0') ;}
		if(N == 2){
			long vv = long.Parse(S);
			long cnt = 9;
			for(int i=10;i<=vv;i++){
				var str = i.ToString();
				if(str[0] == str[1]) cnt++;
			}
			return cnt;
		}
		
		long sum = 0;
		long v = 9;
		long last = 1;
		for(int i=1;i<N;i++){
			sum += v;
			last = v;
			if(i % 2 == 0) v = (v * 10) % mod;
		}
		
		int ll = N / 2; if(N % 2 == 0) ll--;
		
		long[] ten = new long[N+1];
		ten[0] = 1;
		for(int i=1;i<=N;i++){
			ten[i] = ten[i-1] * 10;
			ten[i] %= mod;
		}
		
		for(int i=0;i<=ll;i++){
			if(S[i] == '0') continue;
			sum += (S[i] - '1') * ten[ll - i];
			sum %= mod;
		}
		
		char[] rev = new char[N];
		for(int i=0;i<=ll;i++) rev[i] = rev[N - 1 - i] = S[i];
		var ret = cmp(S,rev);
		if(ret >= 0) sum += 1; sum %= mod;
		
		return sum;
		
	}
	
	int cmp(String S, char[] ca){
		for(int i=0;i<S.Length;i++){
			if(S[i] > ca[i]) return 1;
			if(S[i] < ca[i]) return -1;
		}
		return 0;
	}
	
	
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0