Submission #2526023
Source Code Expand
#include <stack> #include <queue> #include <cstdio> #include <iostream> #include <stdio.h> #include <algorithm> #include <math.h> #include <string> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define Rep(i,n0,n) for(int i=n0;i<n;i++) #define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++) #define INF (1<<29) #define test cout << "test" << endl; int N; int tab[100000]={0}; int t[10000]; int min(int a,int b){ return (a>b)? b:a; } int abs(int a,int b){ return (a>b)? a-b:b-a; } //tab[0]=ここからt[N-1]までの最短距離 int dp(int a){ if(a==N-1){ return 0; } if(tab[a]!=INF){ return tab[a]; } if(a==N-2){ return tab[a]=abs(t[N-1],t[N-2]); } return tab[a]=min(dp(a+1)+abs(t[a],t[a+1]),dp(a+2)+abs(t[a],t[a+2])); } int main (){ cin >>N; rep(i,N){ cin >>t[i]; tab[i]=INF; } cout << dp(0) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | k_karen |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 932 Byte |
Status | WA |
Exec Time | 31 ms |
Memory | 640 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 1 ms | 256 KB |
sample_02.txt | AC | 1 ms | 256 KB |
sample_03.txt | AC | 1 ms | 256 KB |
subtask1_01.txt | AC | 1 ms | 256 KB |
subtask1_02.txt | AC | 1 ms | 256 KB |
subtask1_03.txt | AC | 1 ms | 256 KB |
subtask1_04.txt | WA | 31 ms | 640 KB |
subtask1_05.txt | WA | 31 ms | 640 KB |
subtask1_06.txt | WA | 31 ms | 640 KB |
subtask1_07.txt | WA | 31 ms | 640 KB |