結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー |
![]() |
提出日時 | 2017-06-10 00:07:41 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 1,000 ms |
コード長 | 2,048 bytes |
コンパイル時間 | 1,424 ms |
コンパイル使用メモリ | 117,736 KB |
実行使用メモリ | 27,216 KB |
最終ジャッジ日時 | 2024-07-23 18:29:46 |
合計ジャッジ時間 | 2,747 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; if(i==0){ sum += (S[i] - '1') * ten[ll - i]; } else { sum += (S[i] - '0') * 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));} }