Submission #1147618

#TimeUsernameProblemLanguageResultExecution timeMemory
1147618leo12345Coin Collecting (JOI19_ho_t4)Java
0 / 100
44 ms10576 KiB
import java.io.*; import java.util.*; public class joi2019_ho_t4 { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int N = Integer.parseInt(bufferedReader.readLine()); long ans = 0; int[][] dp = new int[N + 1][3]; // Procesar las posiciones for (int i = 1; i <= 2 * N; i++) { st = new StringTokenizer(bufferedReader.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); if (x > N) { ans += (x - N); x = N; } if (x < 1) { ans += (1 - x); x = 1; } if (y > 2) { ans += (y - 2); y = 2; } if (y < 1) { ans += (1 - y); y = 1; } dp[x][y]++; if (i <= N) { dp[i][1]--; dp[i][2]--; } } // Ajustes finales for (int i = 1; i <= N; i++) { if (dp[i][1] < 0 && dp[i][2] > 0) { int m = Math.min(-dp[i][1], dp[i][2]); ans += m; dp[i][1] += m; dp[i][2] -= m; } if (dp[i][1] > 0 && dp[i][2] < 0) { int m = Math.min(dp[i][1], -dp[i][2]); ans += m; dp[i][1] -= m; dp[i][2] += m; } ans += Math.abs(dp[i][1]) + Math.abs(dp[i][2]); dp[i + 1][1] += dp[i][1]; dp[i + 1][2] += dp[i][2]; } // Imprimir el resultado System.out.println(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...