結果
| 問題 |
No.528 10^9と10^9+7と回文
|
| ユーザー |
kuuso1
|
| 提出日時 | 2017-06-10 00:04:31 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,978 bytes |
| コンパイル時間 | 918 ms |
| コンパイル使用メモリ | 114,272 KB |
| 実行使用メモリ | 29,524 KB |
| 最終ジャッジ日時 | 2024-09-22 20:29:59 |
| 合計ジャッジ時間 | 2,571 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 24 |
コンパイルメッセージ
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;
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));}
}
kuuso1