Submission #1086295

#TimeUsernameProblemLanguageResultExecution timeMemory
1086295Oz121Sateliti (COCI20_satellti)Java
0 / 110
62 ms9568 KiB
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { FastIO io = new FastIO(); ArrayList<Row> arr = new ArrayList<>(); int num = io.nextInt(); int m = io.nextInt(); for (int i = 0;i<num;i++) { String s = io.next(); ArrayList<Integer> r = new ArrayList<>(); for (int j = 0;j<m;j++) { if (s.charAt(j)=='*') r.add(0); else r.add(1); } arr.add(new Row(r)); } int ansR = 0; int ansC = 0; int ans = -1; for (int r = 1;r<=num;r++) { Row move = arr.remove(0); arr.add(move); //System.out.println(arr); int count = 0; for (int i = 0;i<num;i++) { if (arr.get(i).numZ==m) count += m; else { ArrayList<Integer> idx = new ArrayList<>(); //list of indices with 1 for (int j = 0;j<m;j++) { if (arr.get(i).list.get(j)==1) idx.add(j); } if (idx.isEmpty()) continue; int c = idx.get(idx.size()-1)+1; int tempAns = idx.get(0)+m-idx.get(idx.size()-1)-1; for (int j = 0;j<idx.size()-1;j++) { if (idx.get(j+1)-idx.get(j)-1>tempAns) { tempAns = idx.get(j+1)-idx.get(j)-1; c = idx.get(j)+1; } } if (count+tempAns>ans) {ansR = r; ansC = c; ans = count+tempAns;} break; } } } for (int r = 0;r<ansR;r++) { Row move = arr.remove(0); arr.add(move); } //System.out.println(ansR+" "+ansC); for (int i = 0;i<num;i++) { for (int j = 0;j<m;j++) { int temp = arr.get(i).list.get((j+ansC)%m); if (temp==0) io.print('*'); else io.print('.'); } io.println(); } io.close(); } public static class Row { ArrayList<Integer> list; int numZ; public Row (ArrayList<Integer> list) { this.list = list; for (int i : list) { if (i==0) numZ++; } } @Override public String toString() { return list.toString(); } } public static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar; private int numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) { return -1; // end of file } } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public int nextInt() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...