Submission #285773

#TimeUsernameProblemLanguageResultExecution timeMemory
285773cprayer개구리 (KOI13_frog)C++17
Compilation error
0 ms0 KiB
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class frog { public static void main(String[] args) { Problems problems = new Problems(); problems.solve(); } } class Problems { Parser parser = new Parser(); void solve() { int t = 1; for (int i = 0; i < t; i++) { Problem problem = new Problem(); problem.solve(i); } } class Problem { int N; int r; int d; int[] f; List<Point> points = new ArrayList<>(); public Problem() { N = parser.parseInt(); r = parser.parseInt(); points.add(new Point(0, 0, 0)); for (int i = 1; i <= N; i++) { int x = parser.parseInt(); int y = parser.parseInt(); if (x == 0 && y == 0) { continue; } points.add(new Point(x, y, i)); } d = parser.parseInt(); f = new int[N + 1]; for (int i = 0; i <= N; i++) { f[i] = i; } } void solve(int testCase) { points.sort((o1, o2) -> { if (o1.y != o2.y) { return Integer.compare(o1.y, o2.y); } return Integer.compare(o1.x, o2.x); }); merge(points); for (int i = 0; i < points.size(); i++) { Point p = points.get(i); int t = p.x; p.x = p.y; p.y = t; } points.sort((o1, o2) -> { if (o1.y != o2.y) { return Integer.compare(o1.y, o2.y); } return Integer.compare(o1.x, o2.x); }); merge(points); int ans = 0; for (int i = 0; i < points.size(); i++) { Point p = points.get(i); if (find(p.index) == 0) { ans = Math.max(ans, p.x + p.y + 2 * r); } } System.out.println(ans); } void merge(List<Point> sorted) { TreeMap<Integer, Point> all = new TreeMap<>(); int leftKey = 0; int leftVal = sorted.get(0).y; int length = sorted.size(); for (int rightKey = 0; rightKey < length; rightKey++) { int rightVal = sorted.get(rightKey).y; while (leftVal + r < rightVal) { Point deleted = sorted.get(leftKey); all.remove(deleted.x, deleted); leftKey += 1; leftVal = sorted.get(leftKey).y; } Point point = sorted.get(rightKey); all.put(point.x, point); Map.Entry<Integer, Point> el = all.floorEntry(point.x - 1); Map.Entry<Integer, Point> er = all.ceilingEntry(point.x + 1); if (el != null && point.x <= el.getValue().x + r + d) { merge(el.getValue().index, point.index); } if (er != null && er.getValue().x <= point.x + r + d) { merge(er.getValue().index, point.index); } } } void merge(int a, int b) { a = find(a); b = find(b); if (a == b) { return; } if (a > b) { int t = a; a = b; b = t; } f[b] = a; } int find(int v) { return f[v] == v ? v : (f[v] = find(f[v])); } class Point { int x, y, index; public Point(int x, int y, int index) { this.x = x; this.y = y; this.index = index; } } } } class Parser { private final Iterator<String> stringIterator; private final Deque<String> inputs; Parser() { this(System.in); } Parser(InputStream in) { BufferedReader br = new BufferedReader(new InputStreamReader(in)); stringIterator = br.lines().iterator(); inputs = new ArrayDeque<>(); } void fill() { while (inputs.isEmpty()) { if (!stringIterator.hasNext()) throw new NoSuchElementException(); inputs.addAll(Arrays.asList(stringIterator.next().split(" "))); while (!inputs.isEmpty() && inputs.getFirst().isEmpty()) { inputs.removeFirst(); } } } Integer parseInt() { fill(); if (!inputs.isEmpty()) { return Integer.parseInt(inputs.pollFirst()); } throw new NoSuchElementException(); } Long parseLong() { fill(); if (!inputs.isEmpty()) { return Long.parseLong(inputs.pollFirst()); } throw new NoSuchElementException(); } Double parseDouble() { fill(); if (!inputs.isEmpty()) { return Double.parseDouble(inputs.pollFirst()); } throw new NoSuchElementException(); } String parseString() { fill(); return inputs.removeFirst(); } }

Compilation message (stderr)

frog.cpp:1:1: error: 'import' does not name a type
    1 | import java.io.BufferedReader;
      | ^~~~~~
frog.cpp:2:1: error: 'import' does not name a type
    2 | import java.io.InputStream;
      | ^~~~~~
frog.cpp:3:1: error: 'import' does not name a type
    3 | import java.io.InputStreamReader;
      | ^~~~~~
frog.cpp:4:1: error: 'import' does not name a type
    4 | import java.util.*;
      | ^~~~~~
frog.cpp:6:1: error: expected unqualified-id before 'public'
    6 | public class frog {
      | ^~~~~~
frog.cpp:16:5: error: 'Parser' does not name a type
   16 |     Parser parser = new Parser();
      |     ^~~~~~
frog.cpp:32:12: error: expected unqualified-id before '[' token
   32 |         int[] f;
      |            ^
frog.cpp:33:9: error: 'List' does not name a type
   33 |         List<Point> points = new ArrayList<>();
      |         ^~~~
frog.cpp:35:15: error: expected ':' before 'Problem'
   35 |         public Problem() {
      |               ^~~~~~~~
      |               :
frog.cpp:93:20: error: 'List' has not been declared
   93 |         void merge(List<Point> sorted) {
      |                    ^~~~
frog.cpp:93:24: error: expected ',' or '...' before '<' token
   93 |         void merge(List<Point> sorted) {
      |                        ^
frog.cpp:149:19: error: expected ':' before 'Point'
  149 |             public Point(int x, int y, int index) {
      |                   ^~~~~~
      |                   :
frog.cpp:154:10: error: expected ';' after class definition
  154 |         }
      |          ^
      |          ;
frog.cpp:156:6: error: expected ';' after class definition
  156 |     }
      |      ^
      |      ;
frog.cpp:158:2: error: expected ';' after class definition
  158 | }
      |  ^
      |  ;
frog.cpp: In member function 'void Problems::solve()':
frog.cpp:22:31: error: conversion from 'Problems::Problem*' to non-scalar type 'Problems::Problem' requested
   22 |             Problem problem = new Problem();
      |                               ^~~~~~~~~~~~~
frog.cpp: In constructor 'Problems::Problem::Problem()':
frog.cpp:36:17: error: 'parser' was not declared in this scope
   36 |             N = parser.parseInt();
      |                 ^~~~~~
frog.cpp:39:13: error: 'points' was not declared in this scope; did you mean 'Point'?
   39 |             points.add(new Point(0, 0, 0));
      |             ^~~~~~
      |             Point
frog.cpp:50:13: error: 'f' was not declared in this scope
   50 |             f = new int[N + 1];
      |             ^
frog.cpp: In member function 'void Problems::Problem::solve(int)':
frog.cpp:57:13: error: 'points' was not declared in this scope; did you mean 'Point'?
   57 |             points.sort((o1, o2) -> {
      |             ^~~~~~
      |             Point
frog.cpp:57:26: error: 'o1' was not declared in this scope
   57 |             points.sort((o1, o2) -> {
      |                          ^~
frog.cpp:57:30: error: 'o2' was not declared in this scope
   57 |             points.sort((o1, o2) -> {
      |                              ^~
frog.cpp:57:37: error: expected unqualified-id before '{' token
   57 |             points.sort((o1, o2) -> {
      |                                     ^
frog.cpp:68:27: error: 'int Problems::Problem::Point::x' is private within this context
   68 |                 int t = p.x;
      |                           ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:69:19: error: 'int Problems::Problem::Point::x' is private within this context
   69 |                 p.x = p.y;
      |                   ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:69:25: error: 'int Problems::Problem::Point::y' is private within this context
   69 |                 p.x = p.y;
      |                         ^
frog.cpp:147:20: note: declared private here
  147 |             int x, y, index;
      |                    ^
frog.cpp:70:19: error: 'int Problems::Problem::Point::y' is private within this context
   70 |                 p.y = t;
      |                   ^
frog.cpp:147:20: note: declared private here
  147 |             int x, y, index;
      |                    ^
frog.cpp:73:37: error: expected unqualified-id before '{' token
   73 |             points.sort((o1, o2) -> {
      |                                     ^
frog.cpp:85:28: error: 'int Problems::Problem::Point::index' is private within this context
   85 |                 if (find(p.index) == 0) {
      |                            ^~~~~
frog.cpp:147:23: note: declared private here
  147 |             int x, y, index;
      |                       ^~~~~
frog.cpp:86:27: error: 'Math' was not declared in this scope
   86 |                     ans = Math.max(ans, p.x + p.y + 2 * r);
      |                           ^~~~
frog.cpp:86:43: error: 'int Problems::Problem::Point::x' is private within this context
   86 |                     ans = Math.max(ans, p.x + p.y + 2 * r);
      |                                           ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:86:49: error: 'int Problems::Problem::Point::y' is private within this context
   86 |                     ans = Math.max(ans, p.x + p.y + 2 * r);
      |                                                 ^
frog.cpp:147:20: note: declared private here
  147 |             int x, y, index;
      |                    ^
frog.cpp:90:13: error: 'System' was not declared in this scope
   90 |             System.out.println(ans);
      |             ^~~~~~
frog.cpp: In member function 'void Problems::Problem::merge(int)':
frog.cpp:95:13: error: 'TreeMap' was not declared in this scope
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |             ^~~~~~~
frog.cpp:95:21: error: 'Integer' was not declared in this scope
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                     ^~~~~~~
frog.cpp:95:35: error: expected primary-expression before '>' token
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                                   ^
frog.cpp:95:37: error: 'all' was not declared in this scope
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                                     ^~~
frog.cpp:95:47: error: 'TreeMap' does not name a type
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                                               ^~~~~~~
frog.cpp:95:55: error: expected primary-expression before '>' token
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                                                       ^
frog.cpp:95:57: error: expected primary-expression before ')' token
   95 |             TreeMap<Integer, Point> all = new TreeMap<>();
      |                                                         ^
frog.cpp:98:27: error: 'sorted' was not declared in this scope
   98 |             int leftVal = sorted.get(0).y;
      |                           ^~~~~~
frog.cpp:104:40: error: 'int Problems::Problem::Point::x' is private within this context
  104 |                     all.remove(deleted.x, deleted);
      |                                        ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:110:31: error: 'int Problems::Problem::Point::x' is private within this context
  110 |                 all.put(point.x, point);
      |                               ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:112:17: error: 'Map' was not declared in this scope
  112 |                 Map.Entry<Integer, Point> el = all.floorEntry(point.x - 1);
      |                 ^~~
frog.cpp:112:41: error: expected primary-expression before '>' token
  112 |                 Map.Entry<Integer, Point> el = all.floorEntry(point.x - 1);
      |                                         ^
frog.cpp:112:43: error: 'el' was not declared in this scope
  112 |                 Map.Entry<Integer, Point> el = all.floorEntry(point.x - 1);
      |                                           ^~
frog.cpp:112:69: error: 'int Problems::Problem::Point::x' is private within this context
  112 |                 Map.Entry<Integer, Point> el = all.floorEntry(point.x - 1);
      |                                                                     ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:113:41: error: expected primary-expression before '>' token
  113 |                 Map.Entry<Integer, Point> er = all.ceilingEntry(point.x + 1);
      |                                         ^
frog.cpp:113:43: error: 'er' was not declared in this scope; did you mean 'r'?
  113 |                 Map.Entry<Integer, Point> er = all.ceilingEntry(point.x + 1);
      |                                           ^~
      |                                           r
frog.cpp:113:71: error: 'int Problems::Problem::Point::x' is private within this context
  113 |                 Map.Entry<Integer, Point> er = all.ceilingEntry(point.x + 1);
      |                                                                       ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:115:27: error: 'null' was not declared in this scope
  115 |                 if (el != null && point.x <= el.getValue().x + r + d) {
      |                           ^~~~
frog.cpp:115:41: error: 'int Problems::Problem::Point::x' is private within this context
  115 |                 if (el != null && point.x <= el.getValue().x + r + d) {
      |                                         ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:116:54: error: 'int Problems::Problem::Point::index' is private within this context
  116 |                     merge(el.getValue().index, point.index);
      |                                                      ^~~~~
frog.cpp:147:23: note: declared private here
  147 |             int x, y, index;
      |                       ^~~~~
frog.cpp:119:27: error: 'null' was not declared in this scope
  119 |                 if (er != null && er.getValue().x <= point.x + r + d) {
      |                           ^~~~
frog.cpp:119:60: error: 'int Problems::Problem::Point::x' is private within this context
  119 |                 if (er != null && er.getValue().x <= point.x + r + d) {
      |                                                            ^
frog.cpp:147:17: note: declared private here
  147 |             int x, y, index;
      |                 ^
frog.cpp:120:54: error: 'int Problems::Problem::Point::index' is private within this context
  120 |                     merge(er.getValue().index, point.index);
      |                                                      ^~~~~
frog.cpp:147:23: note: declared private here
  147 |             int x, y, index;
      |                       ^~~~~
frog.cpp: In member function 'void Problems::Problem::merge(int, int)':
frog.cpp:139:13: error: 'f' was not declared in this scope
  139 |             f[b] = a;
      |             ^
frog.cpp: In member function 'int Problems::Problem::find(int)':
frog.cpp:143:20: error: 'f' was not declared in this scope
  143 |             return f[v] == v ? v : (f[v] = find(f[v]));
      |                    ^
frog.cpp: In constructor 'Problems::Problem::Point::Point(int, int, int)':
frog.cpp:150:22: error: request for member 'x' in '(Problems::Problem::Point*)this', which is of pointer type 'Problems::Problem::Point*' (maybe you meant to use '->' ?)
  150 |                 this.x = x;
      |                      ^
frog.cpp:151:22: error: request for member 'y' in '(Problems::Problem::Point*)this', which is of pointer type 'Problems::Problem::Point*' (maybe you meant to use '->' ?)
  151 |                 this.y = y;
      |                      ^
frog.cpp:152:22: error: request for member 'index' in '(Problems::Problem::Point*)this', which is of pointer type 'Problems::Problem::Point*' (maybe you meant to use '->' ?)
  152 |                 this.index = index;
      |                      ^~~~~
frog.cpp: At global scope:
frog.cpp:161:12: error: expected ':' before 'final'
  161 |     private final Iterator<String> stringIterator;
      |            ^~~~~~
      |            :
frog.cpp:161:13: error: 'final' does not name a type
  161 |     private final Iterator<String> stringIterator;
      |             ^~~~~
frog.cpp:162:12: error: expected ':' before 'final'
  162 |     private final Deque<String> inputs;
      |            ^~~~~~
      |            :
frog.cpp:162:13: error: 'final' does not name a type
  162 |     private final Deque<String> inputs;
      |             ^~~~~
frog.cpp:168:23: error: expected ')' before 'in'
  168 |     Parser(InputStream in) {
      |           ~           ^~~
      |                       )
frog.cpp:184:5: error: 'Integer' does not name a type
  184 |     Integer parseInt() {
      |     ^~~~~~~
frog.cpp:192:5: error: 'Long' does not name a type; did you mean 'long'?
  192 |     Long parseLong() {
      |     ^~~~
      |     long
frog.cpp:200:5: error: 'Double' does not name a type; did you mean 'double'?
  200 |     Double parseDouble() {
      |     ^~~~~~
      |     double
frog.cpp:208:5: error: 'String' does not name a type
  208 |     String parseString() {
      |     ^~~~~~
frog.cpp:212:2: error: expected ';' after class definition
  212 | }
      |  ^
      |  ;
frog.cpp: In constructor 'Parser::Parser()':
frog.cpp:165:14: error: 'System' was not declared in this scope
  165 |         this(System.in);
      |              ^~~~~~
frog.cpp:165:23: error: expression cannot be used as a function
  165 |         this(System.in);
      |                       ^
frog.cpp: In member function 'void Parser::fill()':
frog.cpp:175:16: error: 'inputs' was not declared in this scope
  175 |         while (inputs.isEmpty()) {
      |                ^~~~~~
frog.cpp:176:18: error: 'stringIterator' was not declared in this scope
  176 |             if (!stringIterator.hasNext()) throw new NoSuchElementException();
      |                  ^~~~~~~~~~~~~~
frog.cpp:176:54: error: expected type-specifier before 'NoSuchElementException'
  176 |             if (!stringIterator.hasNext()) throw new NoSuchElementException();
      |                                                      ^~~~~~~~~~~~~~~~~~~~~~
frog.cpp:177:27: error: 'Arrays' was not declared in this scope
  177 |             inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
      |                           ^~~~~~
frog.cpp:177:41: error: 'stringIterator' was not declared in this scope
  177 |             inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
      |                                         ^~~~~~~~~~~~~~