結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
![]() |
提出日時 | 2015-11-23 14:02:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 6,629 bytes |
コンパイル時間 | 1,058 ms |
コンパイル使用メモリ | 112,964 KB |
実行使用メモリ | 27,496 KB |
最終ジャッジ日時 | 2024-09-13 17:15:24 |
合計ジャッジ時間 | 3,343 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
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.Generic;using System.Linq;using System.IO;using System.Text;namespace Solver{class Program{const int M = 1000000007;const double eps = 1e-9;static void Main(){var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };var sc = new Scan();// var s1 = new sol1();var s2 = new sol2();var a = sc.LongArr;sw.WriteLine(s2.run(a[0], a[1]));sw.Flush();}}class sol1{public int run(int a, int b){var sb = new StringBuilder();for (int i = a; i <= b; i++)sb.Append(i);var s = sb.ToString();int ans = 0;for (int i = 0; i < s.Length - 1; i++)if (s[i] == '1' && s[i + 1] == '2')++ans;return ans;}}class sol2{public long run(long a, long b){var s = (a - 1).ToString();if (s[s.Length - 1] == '1' && a.ToString()[0] == '2')return count(b) - count(a - 1) - 1;return count(b) - count(a - 1);}long count(long a){if (a < 2) return 0;if (a < 12) return 1;var s = a.ToString();int n = s.Length;long ret = 1;var l = new long[n];l[1] = 1;for (int i = 1; i < n - 1; i++)l[i + 1] = l[i] * 10;for (int i = 0; i < n - 1; i++){if (i == 0){if (s[0] == '1'){if (s[1] == '2'){if (n == 2)return 2;ret += long.Parse(s.Substring(2)) + 1;}else if (s[1] > '2')ret += l[n - 1];}else if (s[0] == '2'){if (s[n - 1] > '1'){if (n == 2)return 3;ret += long.Parse(s.Substring(1, n - 2)) + 1;}else{if (n == 2)return 2;ret += long.Parse(s.Substring(1, n - 2));}ret += l[n - 1];}elseret += l[n - 1] * 2;continue;}ret += l[n - i - 1];if (s[i] == '1'){if (s[i + 1] == '2'){if (i + 2 == n)ret += long.Parse(s.Substring(0, i)) * l[n - i - 1] + 1;elseret += long.Parse(s.Substring(0, i)) * l[n - i - 1] + long.Parse(s.Substring(i + 2)) + 1;}else if (s[i + 1] > '2')ret += (long.Parse(s.Substring(0, i)) + 1) * l[n - i - 1];elseret += long.Parse(s.Substring(0, i)) * l[n - i - 1];}else if (s[i] > '1')ret += (long.Parse(s.Substring(0, i)) + 1) * l[n - i - 1];elseret += long.Parse(s.Substring(0, i)) * l[n - i - 1];}return ret;}}class Scan{public int Int { get { return int.Parse(Console.ReadLine().Trim()); } }public long Long { get { return long.Parse(Console.ReadLine().Trim()); } }public string Str { get { return Console.ReadLine().Trim(); } }public int[] IntArr { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } }public int[] IntArrWithSep(char sep) { return Console.ReadLine().Trim().Split(sep).Select(int.Parse).ToArray(); }public long[] LongArr { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); } }public double[] DoubleArr { get { return Console.ReadLine().Split().Select(double.Parse).ToArray(); } }public string[] StrArr { get { return Console.ReadLine().Trim().Split(); } }public List<int> IntList { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToList(); } }public List<long> LongList { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToList(); } }public void Multi(out int a, out int b) { var arr = IntArr; a = arr[0]; b = arr[1]; }public void Multi(out int a, out int b, out int c) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; }public void Multi(out int a, out int b, out int c, out int d) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; }public void Multi(out int a, out string b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1]; }public void Multi(out int a, out int b, out string c) { var arr = StrArr; a = int.Parse(arr[0]); b = int.Parse(arr[1]); c = arr[2]; }public void Multi(out int a, out char b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1][0]; }public void Multi(out char a, out int b) { var arr = StrArr; a = arr[0][0]; b = int.Parse(arr[1]); }public void Multi(out long a, out long b) { var arr = LongArr; a = arr[0]; b = arr[1]; }public void Multi(out long a, out int b) { var arr = LongArr; a = arr[0]; b = (int)arr[1]; }public void Multi(out string a, out string b) { var arr = StrArr; a = arr[0]; b = arr[1]; }}class mymath{int M;const double eps = 1e-9;public mymath(int M) { this.M = M; }public long pow(long a, long b){if (b == 0) return 1;if (b == 1) return a % M;long t = pow(a, b / 2);if ((b & 1) == 0) return t * t % M;else return t * t % M * a % M;}public long gcd(long a, long b){while (b != 0){var t = a % b;a = b;b = t;}return a;}public long lcm(int a, int b) { return (a * b) / gcd(a, b); }}}