Submission #10099708
Source Code Expand
#include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <cstring> #include <queue> #include <set> #include <map> #include <functional> #include <cmath> #define SIZE 100005 using namespace std; typedef long long int ll; typedef pair <int,int> P; int L[SIZE],R[SIZE]; int X[SIZE]; int n,D; int main() { scanf("%d %d",&n,&D); for(int i=0;i<n;i++) scanf("%d",&X[i]); int to=0; for(int i=0;i<n;i++) { while(X[i]-X[to]>D) to++; L[i]=to; } to=n-1; for(int i=n-1;i>=0;i--) { while(X[to]-X[i]>D) to--; R[i]=to; } ll ret=0; for(int i=0;i<n;i++) { ret+=(ll) (i-L[i])*(ll) (R[i]-i); ret-=(ll) (R[i]-i-1)*(ll) (R[i]-i)/2; } printf("%lld\n",ret); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 徒歩圏内 |
User | TsubaMukku |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 751 Byte |
Status | AC |
Exec Time | 14 ms |
Memory | 1280 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d",&n,&D); ^ ./Main.cpp:24:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for(int i=0;i<n;i++) scanf("%d",&X[i]); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
All | 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 | AC | 14 ms | 1280 KB |
02.txt | AC | 12 ms | 1280 KB |
03.txt | AC | 12 ms | 1280 KB |
04.txt | AC | 14 ms | 1280 KB |
05.txt | AC | 14 ms | 1280 KB |
06.txt | AC | 13 ms | 1280 KB |
07.txt | AC | 12 ms | 1280 KB |
08.txt | AC | 11 ms | 1280 KB |
09.txt | AC | 1 ms | 128 KB |
10.txt | AC | 13 ms | 1280 KB |
11.txt | AC | 13 ms | 1280 KB |
12.txt | AC | 13 ms | 1280 KB |
sample-01.txt | AC | 1 ms | 128 KB |
sample-02.txt | AC | 1 ms | 128 KB |
sample-03.txt | AC | 1 ms | 128 KB |
sample-04.txt | AC | 1 ms | 128 KB |