Submission #2602026


Source Code Expand

Copy
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    int D = Integer.parseInt(sc.next());
    
    long X[] = new long[N];
    for (int i = 0; i < N; i++) {
      X[i] = Long.parseLong(sc.next());
    }
    
    long ans = 0;
    for (int i = 0; i < N - 2; i++) {
      for (int k = i + 2; k < N; k++) {
        if (X[k] - X[i] > 2 * D) {
          break;
        } else if (X[k] - X[i] <= D) {
          continue;
        }
        for (int j = i + 1; j < k; j++) {
          if (X[k] - X[j] <= D && X[j] - X[i] <= D) {
            ans++;
          } else if (X[j] - X[i] > D) {
            break;
          }
        }
      }
    }
    System.out.println(ans);
  }
}

Submission Info

Submission Time
Task C - 徒歩圏内
User asuma
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 840 Byte
Status
Exec Time 2109 ms
Memory 47384 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 0 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01.txt 2109 ms 42752 KB
02.txt 397 ms 44048 KB
03.txt 2109 ms 47384 KB
04.txt 2109 ms 44440 KB
05.txt 364 ms 42120 KB
06.txt 2109 ms 44864 KB
07.txt 2109 ms 47152 KB
08.txt 345 ms 44488 KB
09.txt 90 ms 21716 KB
10.txt 2109 ms 44852 KB
11.txt 2105 ms 41732 KB
12.txt 408 ms 45560 KB
sample-01.txt 88 ms 18644 KB
sample-02.txt 89 ms 19796 KB
sample-03.txt 90 ms 21844 KB
sample-04.txt 87 ms 19796 KB