| Task: | Kyselyt |
| Sender: | TapaniS |
| Submission time: | 2025-10-19 21:29:05 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.16 s | 1, 2, 3, 4 | details |
| #2 | ACCEPTED | 0.16 s | 1, 2, 3, 4 | details |
| #3 | ACCEPTED | 0.16 s | 1, 3, 4 | details |
| #4 | TIME LIMIT EXCEEDED | -- | 2, 3, 4 | details |
| #5 | TIME LIMIT EXCEEDED | -- | 2, 3, 4 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2, 3, 4 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 3, 4 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3, 4 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 3, 4 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 4 | details |
Code
import java.util.*;
public class kyselyt {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String kokomaara = input.nextLine();
String[] kokomaaraParts = kokomaara.split("\\s+");
int n = Integer.parseInt(kokomaaraParts[0]);
int q = Integer.parseInt(kokomaaraParts[1]);
// int t = Integer.parseInt(input.nextLine());
int[] x = new int[n]; // luvut
int[] a = new int[q]; // alku
int[] b = new int[q]; // loppu
String num = input.nextLine();
String[] numParts = num.split("\\s+");
for (int i = 0; i < n; i++) {
x[i] = Integer.parseInt(numParts[i]);
}
String[] rajat = new String[q]; // numerot
for (int i = 0; i < q; i++) {
rajat[i] = input.nextLine();
String[] rajaParts = rajat[i].split("\\s+");
a[i] = Integer.parseInt(rajaParts[0]);
b[i] = Integer.parseInt(rajaParts[1]);
}
input.close();
// Program here
StringBuilder sb = new StringBuilder();
for (int i = 0; i < q; i++) { // tapaus q
int ans = -1;
int pit = b[i] - a[i] + 1;
float suhde = 0.0f;
int[] counts = new int[101];
// Map<Integer, Integer> counts = new HashMap<>();
for (int i2 = (a[i]-1); i2 <= (b[i]-1); i2++) {
// counts.put(x[i2], counts.getOrDefault(x[i2], 0) + 1);
counts[x[i2]]++;
}
int mostCommon = 0;
int highestCount = 0;
/*
for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {
if (entry.getValue() > highestCount) {
highestCount = entry.getValue();
mostCommon = entry.getKey();
}
}
*/
for (int i3 = 1; i3 <= 100; i3++) {
if (counts[i3] > highestCount) {
highestCount = counts[i3];
mostCommon = i3;
}
}
suhde = (float)highestCount / pit;
if (suhde > 0.5) {
ans = mostCommon;
}
sb.append(ans).append('\n');
} // tapaus q
// tulostus
// System.out.println(dy + " " + dx);
System.out.print(sb.toString());
}
}Test details
Test 1
Group: 1, 2, 3, 4
Verdict: ACCEPTED
| input |
|---|
| 100 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... Truncated |
Test 2
Group: 1, 2, 3, 4
Verdict: ACCEPTED
| input |
|---|
| 100 100 2 1 2 2 1 2 2 2 1 2 2 1 1 1 1 ... |
| correct output |
|---|
| 2 1 1 2 1 ... |
| user output |
|---|
| 2 1 1 2 1 ... Truncated |
Test 3
Group: 1, 3, 4
Verdict: ACCEPTED
| input |
|---|
| 100 100 5 19 44 88 14 79 50 44 14 99 7... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| -1 -1 -1 -1 -1 ... Truncated |
Test 4
Group: 2, 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 5
Group: 2, 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 ... |
| correct output |
|---|
| 1 1 2 1 1 ... |
| user output |
|---|
| (empty) |
Test 6
Group: 2, 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 8 2 6 1 10 4 9 7 8 10 4 2 8 2 ... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| (empty) |
Test 7
Group: 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 141307 493258596 365539511 222... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| (empty) |
Test 8
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 9
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 2 2 2 1 2 2 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 286470749 280175209 741317063 ... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| (empty) |
Test 11
Group: 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 613084013 1000000000 411999902... |
| correct output |
|---|
| -1 -1 -1 -1 1000000000 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 613084013 1000000000 411999902... |
| correct output |
|---|
| 1000000000 1000000000 -1 1000000000 -1 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 3, 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 329574367 965067805 768744535 691214891 21873594 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 107596959 249558965 679275202 760593154 725418770 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 211070558 49212342 651109313 264549124 651109313 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 2 2 2 1 2 1 1 2 2 1 1 1 1 2 1 ... |
| correct output |
|---|
| 1 2 1 1 1 ... |
| user output |
|---|
| (empty) |
