Submission #00174
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | import java.awt.geom.Point2D; import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; public class Main { final static int INF = 1 << 28; final static long LNF = 1L << 60; final static long MOD = 1_000_000_007; final static double EPS = 1e-13; final static double GOLDEN_RATIO = (1.0 + Math. sqrt (5)) / 2.0; Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main().run(); } class Node implements Comparable<Node> { int a; long b; Node( int a, long b) { this .a = a; this .b = b; } @Override public int compareTo(Node node) { if (a != node.a) { return a - node.a; } return Long.compare(b, node.b); } long cal() { long v = pow (10, b); v += MOD - 1; v %= MOD; v *= pow (9, MOD - 2); v %= MOD; v *= a; v %= MOD; return v; } } long cal(ArrayList<Node> list) { int n = list.size(); long tens = 1; long sum = 0; for ( int i = n - 1; 0 <= i; --i) { Node node = list.get(i); sum += (node.cal() * tens) % MOD; sum %= MOD; tens *= pow (10, node.b); tens %= MOD; } return sum; } void run() { int n = ni(); boolean containsZero = false ; ArrayList<Node> list = new ArrayList<>(); TreeMap<Node, Integer> map = new TreeMap<>(); int [] count = new int [10]; for ( int i = 0; i < n; ++i) { int a = ni(); long b = nl(); containsZero |= a == 0; Node node = new Node(a, b); list.add(node); count[a]++; if (map.containsKey(node)) { map.put(node, map.get(node) + 1); } else { map.put(node, 1); } } Collections.sort(list); Node min = new Node(10, Long.MAX_VALUE); if (containsZero) { int index = -1; for ( int i = 0; i < n; ++i) { Node node = list.get(i); if (node.a == 0) { continue ; } if (node.b < min.b) { min = node; index = i; } else if (node.b == min.b && node.a < min.a) { min = node; index = i; } } if (index != -1) { list. remove (index); list.add(0, min); } } System.out.println(cal(list)); long ans = 1; for ( int i = 0; i < n; ++i) { Node node = list.get(i); if (i == 0 && containsZero) { int cnt = map.get(node); ans *= cnt; } else { int cnt = count[node.a]; ans *= cnt; } ans %= MOD; count[node.a]--; } System.out.println(ans); } int ni() { return Integer.parseInt(sc.next()); } long nl() { return sc.nextLong(); } double nd() { return Double.parseDouble(sc.next()); } void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } /** * ユークリッドの互除法 * * @return a と b の最大公約数 */ long gcd( long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } /** * 拡張ユークリッドの互除法 * * @return mx + ny = gcd(m, n)となるような(x, y)を返す */ Pair<Long, Long> gcd_ex( long m, long n) { long [][] mat = _gcd_ex(m, n); return new Pair<>(mat[0][0], mat[0][1]); } long [][] _gcd_ex( long m, long n) { if (n == 0) { return new long [][]{{1, 0}, {0, 1}}; } long k = m / n; long [][] K = new long [][]{{0, 1}, {1, -k}}; long [][] r = _gcd_ex(n, m % n); long [][] dst = new long [2][2]; for ( int y = 0; y < 2; ++y) for ( int x = 0; x < 2; ++x) for ( int i = 0; i < 2; ++i) dst[y][x] += r[y][i] * K[i][x]; return dst; } /** * 繰り返し2乗法を用いたべき乗の実装 * * @return a^r (mod 1,000,000,007) */ long pow ( long a, long r) { long sum = 1; while (r > 0) { if ((r & 1) == 1) { sum *= a; sum %= MOD; } a *= a; a %= MOD; r >>= 1; } return sum; } /** * 組み合わせ * O(n) * * @return {}_nC_r */ long C( int n, int r) { long sum = 1; for ( int i = n; 0 < i; --i) { sum *= i; sum %= MOD; } long s = 1; for ( int i = r; 0 < i; --i) { s *= i; s %= MOD; } sum *= pow (s, MOD - 2); sum %= MOD; long t = 1; for ( int i = n - r; 0 < i; --i) { t *= i; t %= MOD; } sum *= pow (t, MOD - 2); sum %= MOD; return sum; } /** * 黄金分割探索 * * @param left 下限 * @param right 上限 * @param f 探索する関数 * @param comp 上に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue) * 下に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue).reversed() * @return 極値の座標x */ double goldenSectionSearch( double left, double right, Function<Double, Double> f, Comparator<Double> comp) { double c1 = divideInternally(left, right, 1, GOLDEN_RATIO); double c2 = divideInternally(left, right, GOLDEN_RATIO, 1); double d1 = f.apply(c1); double d2 = f.apply(c2); while (right - left > 1e-9) { if (comp.compare(d1, d2) > 0) { right = c2; c2 = c1; d2 = d1; c1 = divideInternally(left, right, 1, GOLDEN_RATIO); d1 = f.apply(c1); } else { left = c1; c1 = c2; d1 = d2; c2 = divideInternally(left, right, GOLDEN_RATIO, 1); d2 = f.apply(c2); } } return right; } /** * [a,b]をm:nに内分する点を返す */ double divideInternally( double a, double b, double m, double n) { return (n * a + m * b) / (m + n); } /** * bitの立っている数が小さい順にループしたいときに使う。 * ex) * <pre> * for (int i = 0; i < 25; ++i) { * int bits = (1 << i) - 1; * long m = C(25, num); * for (j = 0; j < m; ++j) { * ...(25個の中からi個bitが立っている) * if (bits != 0) * bits = next_perm(bits); * } * } * </pre> * * @param v 現在のbit列 * @return 次のbit列 */ int next_perm( int v) { int t = (v | (v - 1)) + 1; return t | ((((t & -t) / (v & -v)) >> 1) - 1); } static class Util { static <T extends Comparable<T>> T max(T a, T b) { if (a.compareTo(b) > 0) { return a; } else { return b; } } static <T extends Comparable<T>> T min(T a, T b) { if (a.compareTo(b) < 0) { return a; } else { return b; } } } /** * from http://gihyo.jp/dev/serial/01/geometry part 6 */ static class Line { double a; double b; double c; /** * 一般形のパラメータから直線を作成する * * @param a xの係数 * @param b yの係数 * @param c 定数項 */ Line( double a, double b, double c) { this .a = a; this .b = b; this .c = c; } /** * 2点(x1, y1), (x2, y2)を通る直線を作成する * * @param x1 1点目のx座標 * @param y1 1点目のy座標 * @param x2 2点目のx座標 * @param y2 2点目のy座標 * @return 直線 */ static Line fromPoints( double x1, double y1, double x2, double y2) { double dx = x2 - x1; double dy = y2 - y1; return new Line(dy, -dx, dx * y1 - dy * x1); } /** * 与えられた直線との交点を返す * * @param l 直線 * @return 交点。2直線が平行の場合はnull */ Point2D getIntersectionPoint(Line l) { double d = a * l.b - l.a * b; if (d == 0.0) { return null; } double x = (b * l.c - l.b * c) / d; double y = (l.a * c - a * l.c) / d; return new Point2D.Double(x, y); } @Override public String toString() { return "a = " + a + ", b = " + b + ", c = " + c; } } static class Line1D { int x1; int x2; // [x1, x2) : 半開空間 Line1D( int x1, int x2) { this .x1 = x1; this .x2 = x2; } boolean isCross(Line1D l) { return isCross(l.x1, l.x2); } boolean isCross( int y1, int y2) { boolean ret = x1 < y2 && y1 < x2; assert ret == new LineSegment(x1, 0, x2, 0).intersects( new LineSegment(y1, 0, y2, 0)); return ret; } } /** * from http://gihyo.jp/dev/serial/01/geometry part 6 */ static public class LineSegment { double x1; double y1; double x2; double y2; LineSegment( double x1, double y1, double x2, double y2) { this .x1 = x1; this .y1 = y1; this .x2 = x2; this .y2 = y2; } Line toLine() { return Line.fromPoints(x1, y1, x2, y2); } boolean intersects(Line l) { double t1 = l.a * x1 + l.b * y1 + l.c; double t2 = l.a * x2 + l.b * y2 + l.c; return t1 * t2 <= 0; } boolean intersects(LineSegment s) { return bothSides(s) && s.bothSides( this ); } // sが自線分の「両側」にあるかどうかを調べる private boolean bothSides(LineSegment s) { double ccw1 = GeomUtils.ccw(x1, y1, s.x1, s.y1, x2, y2); double ccw2 = GeomUtils.ccw(x1, y1, s.x2, s.y2, x2, y2); if (ccw1 == 0 && ccw2 == 0) { // sと自線分が一直線上にある場合 // sのいずれか1つの端点が自線分を内分していれば、sは自線分と共有部分を持つので // trueを返す return internal(s.x1, s.y1) || internal(s.x2, s.y2); } else { // それ以外の場合 // CCW値の符号が異なる場合にtrueを返す return ccw1 * ccw2 <= 0; } } // (x, y)が自線分を内分しているかどうかを調べる private boolean internal( double x, double y) { // (x, y)から端点に向かうベクトルの内積がゼロ以下であれば内分と見なす return GeomUtils.dot(x1 - x, y1 - y, x2 - x, y2 - y) <= 0; } public Point2D getIntersectionPoint(Line l) { if (!intersects(l)) { return null; // 交差しない場合はnullを返す } return l.getIntersectionPoint(toLine()); } public Point2D getIntersectionPoint(LineSegment s) { if (!intersects(s)) { return null; // 交差しない場合はnullを返す } return s.toLine().getIntersectionPoint(toLine()); } /** * from : http://www.deqnotes.net/acmicpc/2d_geometry/lines#distance_between_line_segment_and_point */ double distance( double x0, double y0) { // 端点チェック if (GeomUtils.dot(x2 - x1, y2 - y1, x0 - x1, y0 - y1) < EPS) { return GeomUtils. abs (x0 - x1, y0 - y1); } if (GeomUtils.dot(x1 - x2, y1 - y2, x0 - x2, y0 - y2) < EPS) { return GeomUtils. abs (x0 - x2, y0 - y2); } // 直線と点の距離 return Math. abs (GeomUtils.cross(x2 - x1, y2 - y1, x0 - x1, y0 - y1)) / GeomUtils. abs (x2 - x1, y2 - y1); } double distance(LineSegment l) { if ( this .intersects(l)) { return 0.0; } double min = Double.MAX_VALUE; min = Math.min(min, distance(l.x1, l.y1)); min = Math.min(min, distance(l.x2, l.y2)); min = Math.min(min, l.distance(x1, y1)); min = Math.min(min, l.distance(x2, y2)); return min; } @Override public String toString() { return "(" + x1 + ", " + y1 + ") - (" + x2 + ", " + y2 + ")" ; } } /** * from http://gihyo.jp/dev/serial/01/geometry part 6 */ static class GeomUtils { // 外積 static double cross( double x1, double y1, double x2, double y2) { return x1 * y2 - x2 * y1; } // 内積 static double dot( double x1, double y1, double x2, double y2) { return x1 * x2 + y1 * y2; } // (x1, y1) -> (x2, y2) -> (x3, y3) と進む道のりが半時計回りの場合は正の値、 // 時計回りの場合は負の値、一直線上の場合はゼロを返す static double ccw( double x1, double y1, double x2, double y2, double x3, double y3) { return cross(x2 - x1, y2 - y1, x3 - x2, y3 - y2); } static double ccw(Point2D p1, Point2D p2, Point2D p3) { return ccw(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); } // ベクトルの長さ static double abs ( double x, double y) { return Math. sqrt (x * x + y * y); } // 多角形の内外判定 boolean isIn(ArrayList<LineSegment> list, double x, double y) { int wn = 0; for (LineSegment l : list) { if (l.y1 <= y && l.y2 > y) { double vt = (y - l.y1) / (l.y2 - l.y1); if (x < l.x1 + (vt * (l.x2 - l.x1))) { ++wn; } } if (l.y1 > y && l.y2 <= y) { double vt = (y - l.y1) / (l.y2 - l.y1); if (x < (l.x1 + (vt * (l.x2 - l.x1)))) { --wn; } } } return wn > 0; } } /** */ static class FastScanner { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; public FastScanner(InputStream in) { this .in = in; } private static boolean isPrintableChar( int c) { return 33 <= c && c <= 126; } private boolean hasNextByte() { if (ptr < buflen) { return true ; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false ; } } return true ; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false ; int b = readByte(); if (b == '-' ) { minus = true ; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while ( true ) { if ( '0' <= b && b <= '9' ) { n *= 10; n += b - '0' ; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } } static class Pair<F extends Comparable<F>, S extends Comparable<S>> implements Comparable<Pair<F, S>> { F f; S s; Pair() { } Pair(F f, S s) { this .f = f; this .s = s; } Pair(Pair<F, S> p) { f = p.f; s = p.s; } @Override public int compareTo(Pair<F, S> p) { if (f.compareTo(p.f) != 0) { return f.compareTo(p.f); } return s.compareTo(p.s); } @Override public int hashCode() { return f.hashCode() ^ s.hashCode(); } @Override public boolean equals(Object o) { if ( this == o) { return true ; } if (o == null || this .f == null || this .s == null) { return false ; } if ( this .getClass() != o.getClass()) { return false ; } Pair p = (Pair) o; return this .f.equals(p.f) && this .s.equals(p.s); } @Override public String toString() { return "{" + f.toString() + ", " + s.toString() + "}" ; } } class BIT<T> { int n; ArrayList<T> bit; BiFunction<T, T, T> bif; /** * 1-indexed なBinary Indexed Treeを構築する * * @param n 容量 * @param bif 適用させる関数 * @param sup 初期値 */ BIT( int n, BiFunction<T, T, T> bif, Supplier<T> sup) { this .n = n; bit = new ArrayList<>(n + 1); for ( int i = 0; i < n + 1; ++i) { bit.add(sup.get()); } this .bif = bif; } /** * iの位置の値をvで更新する * * @param i index * @param v 新しい値 */ void set( int i, T v) { for ( int x = i; x <= n; x += x & -x) { bit.set(x, bif.apply(bit.get(x), v)); } } /** * クエリー * * @param defaultValue 初期値 * @param i index * @return [1, i]までfを適用した結果 */ T reduce(T defaultValue, int i) { T ret = defaultValue; for ( int x = i; x > 0; x -= x & -x) { ret = bif.apply(ret, bit.get(x)); } return ret; } } class SegmentTree<T> { int n; ArrayList<T> dat; BiFunction<T, T, T> bif; Supplier<T> sup; /** * 0-indexed なSegment Treeを構築する * * @param n_ 要求容量 * @param bif 適用させる関数 * @param sup 初期値 */ SegmentTree( int n_, BiFunction<T, T, T> bif, Supplier<T> sup) { n = 1; while (n < n_) n *= 2; dat = new ArrayList<>(2 * n - 1); for ( int i = 0; i < 2 * n - 1; ++i) { dat.add(sup.get()); } this .bif = bif; this .sup = sup; } /** * kの位置の値をvで更新する * * @param k index * @param v 新しい値 */ void set( int k, T v) { k += n - 1; dat.set(k, v); while (k > 0) { k = (k - 1) / 2; dat.set(k, bif.apply(dat.get(k * 2 + 1), dat.get(k * 2 + 2))); } } /** * クエリー * * @param l はじめ * @param r おわり * @return [l, r)での演算bifを適用した結果を返す */ T reduce( int l, int r) { return _reduce(l, r, 0, 0, n); } T _reduce( int a, int b, int k, int l, int r) { if (r <= a || b <= l) return sup.get(); if (a <= l && r <= b) return dat.get(k); T vl = _reduce(a, b, k * 2 + 1, l, (l + r) / 2); T vr = _reduce(a, b, k * 2 + 2, (l + r) / 2, r); return bif.apply(vl, vr); } } class UnionFind { int [] par; UnionFind( int n) { par = new int [n]; for ( int i = 0; i < n; ++i) { par[i] = i; } } int find( int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } boolean same( int x, int y) { return find(x) == find(y); } void union ( int x, int y) { x = find(x); y = find(y); if (x == y) { return ; } par[x] = y; } } } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - repdigit |
ユーザー名 | HappyBirthdayUkunikia! |
投稿日時 | 2017-07-07 21:38:13 |
言語 | Java |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 20030 Byte |
最大実行時間 | 520 ms |
最大メモリ使用量 | 62312 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
01_sample1.in | AC | 76 ms | 14760 KB |
1
|
01_sample2.in | AC | 76 ms | 14676 KB |
1
|
01_sample3.in | AC | 69 ms | 14972 KB |
1
|
02_handmake1.in | AC | 72 ms | 14788 KB |
1
|
02_handmake2.in | AC | 67 ms | 14768 KB |
1
|
02_handmake3.in | AC | 81 ms | 13652 KB |
1
|
02_handmake4.in | AC | 78 ms | 13612 KB |
1
|
02_handmake5.in | AC | 76 ms | 16684 KB |
1
|
02_handmake6.in | AC | 88 ms | 14164 KB |
1
|
02_handmake7.in | AC | 67 ms | 14736 KB |
1
|
02_handmake8.in | AC | 73 ms | 15020 KB |
1
|
02_handmake9.in | AC | 66 ms | 14732 KB |
1
|
03_random1.in | AC | 80 ms | 13612 KB |
1
|
03_random2.in | AC | 101 ms | 14096 KB |
1
|
03_random3.in | AC | 110 ms | 13744 KB |
1
|
03_random4.in | AC | 87 ms | 14716 KB |
1
|
03_random5.in | AC | 104 ms | 13988 KB |
1
|
03_random6.in | AC | 96 ms | 14776 KB |
1
|
04_random1.in | WA | 73 ms | 14804 KB |
1
|
04_random2.in | AC | 74 ms | 14904 KB |
1
|
04_random3.in | WA | 76 ms | 15036 KB |
1
|
04_random4.in | AC | 72 ms | 13796 KB |
1
|
04_random5.in | AC | 71 ms | 14372 KB |
1
|
04_random6.in | AC | 76 ms | 16844 KB |
1
|
05_random1.in | WA | 520 ms | 62312 KB |
1
|
05_random2.in | WA | 504 ms | 58212 KB |
1
|
05_random3.in | WA | 517 ms | 59408 KB |
1
|
05_random4.in | WA | 514 ms | 61520 KB |
1
|
06_random1.in | AC | 510 ms | 59036 KB |
1
|
06_random3.in | AC | 513 ms | 61320 KB |
1
|