Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n=int(input())
a=[int(i) for i in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]
for w in range(1,n+1):
#for w in range(1,3,1):
# print(dp[1])
for l in range(n-w+1):
r=l+w
dpl=-dp[l+1][r]+a[l]
dpr=-dp[l][r-1]+a[r-1]
dp[l][r]=max(dpl,dpr)
#print()
#for i in dp:
# print(i)
... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n, dp[3010][3010], a[3010];
LL solve(int l, int r) {
if(l > r) return 0;
LL &ret = dp[l][r];
if(ret != -1) return ret;
LL left = a[l] - solve(l+1, r);
LL right = a[r] - solve(l, r-1);
return ret = max(left, right);
}
int main() {
memset(dp, ... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001]; int arr[3000];
long long int solve(int i,int j)
{ if(i>j)
return 0;
if (dp[i][j]!=-1) return dp[i][j];
dp[i][j]=max(arr[i]-solve(i+1,j),arr[j]-solve(i,j-1));
return dp[i][j];
}
int main()
{int n;
cin>>n;
for(int i=0;i<n;++i)
cin>>ar... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main implements Closeable {
private InputReader in = new InputReader(System.in);
private Pr... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
#define N_MAX 3002
#define ll long long
using namespace std;
int n;
ll a[N_MAX];
ll dp[N_MAX][N_MAX];
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = n; i >= 1; i--)
for(int j = i; j <= n; j++)
dp[i][j] = max(-dp[i + 1][j... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
Scan sc = new Scan();
int n = sc.scanInt();
SolL sol = new SolL(n);
for(int i= 0; i <n; ++i)
sol.arr[i] = sc.scanInt();
sol.sol();
}
}
class... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | dp={}
n=int(input())
nums=list(map(int,input().split()))
#print(dp)
#print(recursive(0,n-1))
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n-1,-1,-1):
for j in range(i,n,1):
dp[i][j]=max(nums[i]-dp[i+1][j],nums[j]-dp[i][j-1])
print(dp[0][n-1])
| PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.NoSuchElementException;
public class Main {
private static Scanner sc;
private static Printer pr;
private static void solve() {
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
long[][] dp = new long[n][n];
for (i... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main {
static long[][] dp;
static long[] arr;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
arr = new long[n];
dp = new long[n][n];
for(int i = 0; i < n; ++i) arr[i] = in.nextInt();
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | /*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
public class Main {
/*********************************************Constants******************************************/
static PrintWriter out=new PrintWriter(new OutputStreamWr... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = Integer.parseInt(in.nextLine());
long[] arr = new long[N];
StringTokenizer s = new StringTokenizer(in.nextLine());
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n = int(input())
A = [int(i) for i in input().split()]
DP = [[0] * n for i in range(n)]
if n % 2 == 1:
for i in range(n):
DP[i][i] = A[i]
else:
for i in range(n):
DP[i][i] = -A[i]
for i in range(1, n):
for l in range(n-i):
if (n - i) % 2 == 1:
DP[l][l+i] = max(DP[l+1][l... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def p_l_2():
n = int(input())
*a, = map(int, input().split())
# dp[i][j]は区間[i,j]が残っているときの最大化
dp = [[-1] * n for _ in range(n)]
for i in range(n):
for l in range(n - i):
r = l + i
if l == r:
dp[l][r] = a[l]
else:
dp[l][r] = ... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<iostream>
using namespace std;
int n;
int v[3005];
long long dp[3005][3005];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=1;i<=n;i++)
dp[i][i]=v[i];
for(int i=n-1;i>=1;i--)
for(int j=i+1;j<=n;j++)
dp[i][j]=max(v[i]-dp[i+1][j],v[j]-dp[i... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n=int(input())
a=list(map(int,input().split()))
dp=[[0]*n for i in range(n)]
for i in range(n):
if n%2==0:
dp[i][i]=-a[i]
else:
dp[i][i]=a[i]
for l in range(1,n):
if n%2==l%2:
for right in range(l,n):
left=right-l
dp[left][right]=min(dp[left+1][right]-a[left],... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int, input().split()))
dp = [[0]*(2*N) for i in range(N)]
for i in range(N):
dp[i][i] = a[i]
dp[i][i+N] = -a[i]
for i in range(1, N+1):
for x in range(N-i):
dp[x][x+i] = max(a[x]+dp[x+1][x+i+N], a[x+i]+dp[x][x+i-1+N])
dp[x][x+i+N] = min(dp[x+1][x+i]-a[x], dp[x]... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
long long dp[3001][3001];
int main(){
int n;cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-1;i>=0;i--){
for(int j=i;j<n;j++){
if(i==j){
dp[i][j]=a[i];
}
else{
... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n = int(input())
a = list(map(int, input().split()))
dp = [[None] * len(a) for _ in a]
for i in range(len(a)-1, -1, -1):
for j in range(i, len(a)):
if i == j:
dp[i][j] = a[i]
continue
dp[i][j] = max(a[j] - dp[i][j-1], a[i] - dp[i+1][j])
print(dp[0][len(a) - 1]) | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | # -*- coding: utf-8 -*-
import sys
N=input()
A=map(int, sys.stdin.readline().split())
dp=[ [ None for i in range(N) ] for j in range(N) ]
for i in range(N-1,-1,-1):
if N%2==0:
dp[i][i]=A[i]*-1
else:
dp[i][i]=A[i]
for i in range(N-2,-1,-1):
for j in range(i+1,N):
t=N-(j-i+1) #残りの要素数
if t%2==0:
if dp... | PYTHON |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, a[3004];
long long dp[3004][3004];
int main() {
cin>>n;
for(int i = 1;i<=n;i++)
cin>>a[i];
for(int i = 1;i<=n;i++)
dp[i][i] = a[i];
for(int i = n-1;i>=0;i--)
for(int j = i+1;j<=n;j++){
dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] s = br.readLine().split(" ");
int[] arr = new int[n + 1];
long[] ... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def deque(a):
n = len(a)
cur = a[:]
nxt = [0] * (n - 1)
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
nxt[i] = max(a[i] - cur[i + 1], a[j] - cur[i])
cur, nxt = nxt, cur
return cur[0]
def main():
input() # n
a = [int(x) for x in ... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | # dp[j][i]=(区間[i,j]が残っているとき次の手番の得点-そうじゃない人の得点)
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
INF=-10**14
dp=[[0]*(i+1) for i in range(n)]
for i in range(n):
dp[i][i]=a[i]
for i in range(1,n):
for j in range(i-1,-1,-1):
dp[i][j]=ma... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main implements Runnable {
// static Scanner in;
static FastReader in;
static PrintWriter out;
static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
static int[][] dirs = {{0, -1}, {1, 0}, {0, ... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int, input().split()))
dp = [[0] * N for i in range(N)]
for i in range(N):
dp[i][i] = a[i]
for i in range(N-1)[::-1]:
for j in range(i+1, N):
dp[i][j] = max(a[i]-dp[i+1][j], a[j]-dp[i][j-1])
print(dp[0][N-1])
| PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def main():
n = int(input())
a = list(map(int, input().split()))
dp=[]
for i in range(n):
dp.append([0] * n)
for i in range(n):
dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
int n;
int a[3005];
ll memo[3005][3005];
ll dp(int l,int r){
if(l==r)return a[l];
if(memo[l][r]!=-1)return memo[l][r];
return memo[l][r]=max(a[l]-dp(l+1,r),-dp(l,r-1)+a[r]);
}
int main(){
cin>>n;
for(int i... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
import static java.lang.System.in;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(in);
int n = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
L = [0] + list(accumulate(A))
dp = [[0]*(n+1) for i in range(n+1)]
for d in range(1, n+1):
for i in range(n+1-d):
dp[i][i+d] = max(A[i] + L[i+d] - L[i+1] - dp[i... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.BufferedInputStream;
import java.util.Scanner;
/**
* Created by Harry on 4/6/20.
*/
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
int n = scanner.nextInt();
long[] A = new long[n];
for... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int N=3e3+5;
ll a[N],dp[N][N];
int main()
{
int n,i,j,L,R;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%lld",&a[i]);
for(L=n;L>=1;L--)
{
for(R=L;R<=n;R++)
{
dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
}
}
prin... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #dp=[[ for i in range(3000)] for j in range(3000)]
n=int(input())
A=list(int(i) for i in input().split())
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n-1,-1,-1):
for j in range(i,n):
if i==j:
dp[i][j]=A[i]
else:
dp[i][j]=max(A[i]-dp[i+1][j],A[j]-dp[i][j-1])
pr... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
So... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll N;
cin>>N;
ll value[N]; ll dp[N][N];
for(ll i=0;i<N;i++)
{
cin>>value[i];
dp[i][i]=value[i];
}
for(ll len=2;len<=N;len++)
{
for(ll i=0;i<=N-len;i++)
{
dp[i][i+len-1]=max(value[i]-dp[i+1][i+len-... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
memo_ls = [[0 for j in range(n)] for i in range(n)]
for j in range(n):
for i in range(j,-1,-1):
if i == j:
memo_ls[i][j] = a_ls[j]
else:
memo_ls[i][j] = max(- memo_ls[i+1][j] + a_ls[i], - memo_l... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<cstdio>
#include<cstring>
const int MAXN=3010;
int n,a[MAXN];
long long f[MAXN][MAXN];
inline long long max(long long x,long long y){
return x>y?x:y;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int len=1;len<=n;len++)
for(int r=1;r<=n;r++){
int l=r-len+1;
if(l<1)
... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Main ans = new Main();
System.out.println(ans.solve());
}
private long solve() {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
long [] array = new long[N+1];
long sum=0;
for(int i=1;i<=N;i... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
dp = [[0]*(n + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][i] = 0
for width in range(1, n + 1):
for l in range(n + 1):
r = width + l
if r <= l or r > n:
continue
if (n ... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <iostream>
using namespace std;
long long b[3001][3001];
int main()
{
int n;
cin >> n;
long long a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
{
b[i][i] = a[i];
for (int j = i - 1; j >= 1; j--)
b[j][i] = max(a[i] - b[j][i - 1], a[j] - b[j + 1][i]);
}
co... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
long long a[N], dp[N][N];
for (int i = 0; i < N; i++) {
cin >> a[i];
}
dp[0][0] = a[0];
for (int j = 1; j < N; j++) {
dp[j][j] = a[j];
for (int i = j-1; i+1; i--) {
dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1])... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def main():
n = int(input())
a = list(map(int, input().split()))
dp = [0] * (n*n)
for i in range(n):
dp[i+i*n] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i+j*n] = max(a[i] - dp[i + 1+j*n], a[j] - dp[i+(j - 1)*n])
print(dp[(n - 1)*n])
main()
| PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n = int(input())
a = list(map(int, input().split()))
dp = [[0]*(n+1) for i in range(n+1)]
for l in range(1,n+1):
for i in range(n+1-l):
j = i+l
if (n-l)%2 == 0:
dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1])
else:
dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1]... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include"bits/stdc++.h"
using namespace std;
int n,a[3001];
long long f[3001][3001];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(n%2)
f[i][i]=a[i];
else
f[i][i]=-a[i];
}
for(int j=1;j<n;j++)
for(int i=1;i+j<=n;i++)
{
if((j+(n%2))%2)
f[i][i+j]=max(f[i+1][i+j]+a[... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
A = [int(a) for a in input().split()]
dp = [[0] * (N+1) for _ in range(N+1)]
for d in range(N):
for l in range(N-d):
r = l + d
if d == 0:
dp[l][r] = A[l] * (-1)**(N+d+1)
else:
s = (-1)**(N+d+1)
dp[l][r] = max(A[l] + dp[l+1][r... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
import static java.lang.System.in;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(in);
int n = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
public class Main {
static Long[][] dp;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] stones = new int[N];
dp = new Long[N + 1][N + 1];
for (int i = 0; i < stones.length; i... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int,input().split()))
X,Y = 0,0
dp = [[0] * (N+1) for i in range(N+1)]
# dp[i][j] ans = dp[1][N]
for i in range(1,N+1):
if N % 2 == 1:
dp[i][i] = a[i-1]
else:
dp[i][i] = -a[i-1]
for i in range(N-1,0,-1):
for j in range(1,N+1):
if i >= j: continue
... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static final Scanner sc = new Scanner(System.in);
static final int MOD = (int) 1E9 + 7;
public static void main(String[] args) {
int N = nint();
int[] a = nints(N, 1, 0);
long[][] dp = new long[N+1][N+... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import ... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll n;
cin>>n;
ll a[n+1];
for(int i=1;i<=n;i++) cin>>a[i];
ll dp[n+1][n+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++) dp[i][i]=a[i];
for(int len=1;len<n;len++){
ll i=1;
for(int j=i+len;j<=n;j++){
dp[i][j]=max(a[i]-dp[i+1][j],a... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.ut... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class Main {
private static final class Score {
final long x;
final lo... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
A = list(map(int,input().split()))
dp = [[0 for j in range(N+1)] for i in range(N+1)]
for t in range(1,N+1):
for i in range(N-t+1):
j = i+t
if (N-t)%2==0:
dp[i][j] = max(dp[i+1][j]+A[i],dp[i][j-1]+A[j-1])
else:
dp[i][j] = min(dp[i+1][j]-A[i],dp[i][j... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N, *A = map(int, open(0).read().split())
dp = [[0] * (N + 1) for _ in range(N + 1)]
for d in range(1, N + 1):
for l in range(N - d + 1):
r = l + d
if (N - d) % 2 == 0:
dp[l][r] = max(
A[l] + dp[l + 1][r],
A[r - 1] + dp[l][r - 1]
)
else... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 |
import java.util.Arrays;
public class Main {
private static void solve() {
int n = ni();
int[] a = na(n);
dp = new long[n][n];
for (long[] v : dp) Arrays.fill(v, Long.MIN_VALUE);
long ret = rec(0, n - 1, a);
System.out.println(ret);
}
static long[][] dp;;
private static long rec... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
impor... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
/**
* Consider small intervals and evaluate them before larger intervals
* @param a
* @return max difference when the game is played optimally
*/
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N=int(input())
a = list(map(int, input().split()))
dp=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
dp[i][i]=a[i-1]
for j in range(1,N+1):
for i in reversed(range(1,N+1)):
if i>j:
continue
if i==j:
dp[i][j]=a[i-1]
if i<j:
dp[i][... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int, input().split()))
dp = [[0]*N for _ in range(N)]
for l in range(N):
for i in range(N):
j = i+l
if j>=N:
continue
if (N-l-1)%2==0:
if i==j:
dp[i][j] = a[i]
else:
dp[i][j] ... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int, input().split()))
S = [0] * (N+1)
for i in range(N):
S[i+1] = S[i] + a[i]
dp = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
dp[i][i] = a[i]
for d in range(1, N):
for i in range(N-d):
dp[i][i+d] = max(a[i] + S[i+d+1] - S[i+1] - dp[i+1][i+d], a[i+d]... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
ll n,a[3010],dp[3010][3010]={};
int main(){
cin>>n;
fr(i,n) cin>>a[i];
fr(i,n){
fr(j,n-i){
ll k=j+i;
if(i==0){dp[j][k]=a[j];continue;}
dp[j][k]=max(a[j]-dp[j+1][k],a[k]-dp[j][k-1]);
... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<cstdio>
#include<algorithm>
using namespace std;
long long n,a[3005],dp[3005][3005];
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
dp[i][i]=a[i];
}
for(int i=n;i>=1;i--)
{
for(int j=i+1;j<=n;j++)
{
dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
}
}
printf("%ll... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Main ans = new Main();
System.out.println(ans.solve());
}
private long solve() {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
long [] array = new long[N+1];
long sum =0;
for(int i=1;i<=N;... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
//int nax = 3005;
long long dp[3005][3005];
int main(){
int n;cin>>n;
long long aa;
vector<long long> arr(n);
for(int i=0;i<n;i++){
cin>>aa;
arr[i] = aa;
}
for(int l=n-1;l>=0;l--){
for(int r=l;r<n;r++){
if(l==r) dp[l][r] = arr[l];
else
dp[l][r] = ma... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | //Problem *
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3005;
int n;ll a[N],dp[N][N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)for(int l=1;l<=n-i+1;l++){
int r=l+i-1;
dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
}
printf("%lld"... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
class ac_dp_l {}
class Main {
public static void main(String[] args) throws IOException {
int n = ri(), a[] = ria(n);
long dp[][] = new long[n][n];
for (long[] row : dp) {
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n=int(input())
a=list(map(int,input().split()))
dp=[[0 for i in range(n+1-j)] for j in range(n+1)]
for le in range(1,n+1):
for i in range(n+1-le):
if le%2==n%2:
ret=dp[le-1][i]+a[i+le-1]
if i+1<=n+1-le:
ret=max(ret,dp[le-1][i+1]+a[i])
dp[le][i]=ret
... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll a,b,c,d;
cin >> a ;
vector<ll> v;
for(ll i=0;i<a;i++)
{
cin >> b;
v.push_back(b);
}
ll dp[a][a];
dp[a-1][a-1]=v[a-1];
for(ll i=a-1;i>=0;--i)
{
for(ll j=i;j<a;j++)
{
if(i==j)
{
dp[i][j]=v[i];
}
... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] deque = new int[n];
for(int i = 0 ; i < n ; i++) {
deque[i] = scan.nextInt();
}
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 3;
int n,a[N];
long long dp[N][N];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int l = n; l >= 1; l--){
for(int r = l; r <= n; r++){
if(l == r)
dp[l][r] = a[l];
else
dp[l]... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | /*
Author: Anthony Ngene
Created: 13/08/2020 - 18:33
*/
import java.io.*;
import java.util.*;
public class Main {
// Service to others is the rent you pay for your room here on earth. - Muhammad Ali
static Long[][][] dp;
static long[] arr;
public static void main(String[] args) throws IOExcept... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = [int(c) for c in input().split()]
dp = [[-1] * N for _ in range(N)]
for L in range(N, -1, -1):
for R in range(L, N):
if L == R:
dp[L][R] = a[L]
else:
dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1])
print(dp[0][N-1])
| PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
in... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
#define NMAX 3005
using namespace std;
int n;
long long a[NMAX],d[NMAX][NMAX];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
d[i][i]=a[i];
for(int i=2;i<=n;i++)
{
for(int j=1;j<=n-i+1;j++)
{
d[j][j+i-1... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] a = new int[N];
for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
long[][] dp = new long[N][N];
for (int i = 0; i < N; i++) d... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main
{
static long MOD=(long) (1e9+7);
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def fun(i,j):
# print(i,j)
if i>j or i>=n or j<0:
return 0
elif i==j:
dp[i][j]=arr[i]
return dp[i][j]
else:
if dp[i][j]==0:
dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))
return dp[i][j]
n=int(input())
dp=[0]*n
for i in range(n):
dp[i]=[0]*n
arr=list(map(int,inpu... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
A = [int(a) for a in input().split()]
dp = [[0]*N for _ in range(N)]
for k in range(N):
for i in range(N-k):
if k == 0:
dp[i][i] = A[i]
continue
dp[i][i+k] = max(A[i]-dp[i+1][i+k], A[i+k]-dp[i][i+k-1])
print(dp[0][N-1]) | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | n=int(input())
v=list(map(int, input().split()))
dp=[[-1] * n for i in range(n)]
def f(a, b):
if a > b:
return 0
elif a == b:
return v[a]
elif dp[a][b] == -1:
c1 = v[a] + min(f(a + 2, b), f(a + 1, b - 1))
c2 = v[b] + min(f(a, b - 2), f(a + 1, b - 1))
dp[a][b] = max(c1... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<int> a(n);
for(int& i : a)
{
scanf("%d", &i);
}
long long dp[n][n];
for(int i = n - 1; i >= 0; i--)
{
for(int j = i; j < n; j++)
{
if(i == j)
dp[i][j] = a[i];
else
dp[i][j]... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException {
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import javax.swing.event.InternalFrameListener;
import java.io.*;
import java.text.*;
import java.util.*;
public class Main {
static InputReader sc = new InputReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
solve... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = scan.nextInt();
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | /*
[ ( ^ _ ^ ) ]
*/
import java.io.*;
import java.util.*;
public class Main {
int INF = (int)1e9;
long MOD = 1000000007;
long max(long...x) {long rs = x[0]; for(long y: x) rs = Math.max(rs, y); return rs;}
long min(long...x) {long rs = x[0]; for(long y: x) rs = Math.min(rs, y); return rs;}
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main (){
int n;
cin>>n;
vector<ll> v(n);
vector<vector<ll>> dp(n, vector<ll>(n));
for(int i=0; i<n; ++i) cin>>v[i];
for(int r=0; r<n; ++r){
for(int l=r; l>=0; --l){
if(l==r) dp[l][r]=v[l];
else dp[l][r]=max(v[l]-dp[l+1][r], v[r]-dp[l... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
private static Scanner in;
private static int n;
private static int[] a;
private static long[][] dp;
public static void main(String[] args) {
in = new Scanner(System.in);
n = in.nextInt();
a = new int[n... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.io.*;
import java.util.*;
class Main {
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputS... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long dp[][] = new long[n][n];
for ( int i = 0; i < n; i++ ) {
dp[i][i] = in.nextInt();
}
in.close();
for ( int col = 1; col < n; col++ ) {
int r = 0, c ... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N=int(input())
a=[int(i) for i in input().split()]
dp=[[0]*(N+1) for i in range(N+1)]
for d in range(1,N+1):
for i in range(N+1-d):
if (N-d)%2==0:
dp[i][i+d]=max(dp[i+1][i+d]+a[i],dp[i][i+d-1]+a[i+d-1])
if (N-d)%2==1:
dp[i][i+d]=min(dp[i+1][i+d],dp[i][i+d-1])
print(2*dp[0][N]-sum(a))
| PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #L
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(N):
S[i+1]=S[i]+a[i]
dp=[[0]*(N+1) for _ in range(N+1)]#[l,r)の範囲が残っているときに取れる最大値
for i in range(1,N+1):#r-lの値
for j in range(N):#lの値
r=j+i
if r>N:
break
l=j
x=a[l]+(S[r]-S[l+1]) - dp[l+1]... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int []a = IntStream.range(0, n).map(x -> in.nextInt()).toArray();
long [][]dp = new long[n][n];
... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF= 1e18L+5;
int main() {
int n;
cin >>n;
ll a[n];
for(int i=0; i<n; i++)
cin >> a[i];
ll dp[n+1][n+1];
for(int r=0; r<n;r++){
for(int l=r;l>=0;l--){
if(l==r)
dp[l][r] = a[l];
else{
dp[l][r] = max(a[l]-dp[l+1][r],a[r]... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include<cstdio>
#define ll long long
#include<algorithm>
ll dp[3050][3050];
int v[3050],n;
bool vis[3050][3050];
ll dfs(int l,int r){
if (l>r)return 0;
if (vis[l][r])return dp[l][r];
vis[l][r]=1;
return dp[l][r]=std::max(v[r]-dfs(l,r-1),v[l]-dfs(l+1,r));
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)scan... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
int a[n+1];
ll dp[n+1];
for(int i=0;i<=n;i++) dp[i] = 0;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=n;i>=1;i--)
{
for(int j=i;j<=n;j++)
{
if(i == j)
{
dp[i] = a[i];
}
... | CPP |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | import java.util.Scanner;
/**
* Deque
*/
public class Main {
public static void main(String[] args) throws Exception {
try (Scanner sc = new Scanner(System.in)) {
int N = sc.nextInt();
long[] A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nex... | JAVA |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | N = int(input())
a = list(map(int, input().split()))
dp = [[0 for i in range(N+1)] for j in range(N+1)]
for len in range(1, N+1):
for i in range(N - len + 1):
j = i + len
if (N - len) % 2 == 0:
dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1])
else:
dp[i][j] = m... | PYTHON3 |
p03171 Educational DP Contest - Deque | Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
* Remove the element at the beginning or the end of a. The player earns x points, whe... | 6 | 0 | def deque(n, arr):
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = arr[i]
for l in range(n-1, -1, -1):
for r in range(l, n):
if l == r:
continue
L = arr[l] - dp[l+1][r]
R = arr[r] - dp[l][r-1]
dp[l][r] = L if L >... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.