Submission #72757575


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vvvl=vector<vector<vector<long long>>>;
using pl=pair<long long,long long>;
using vpl=vector<pair<long long,long long>>;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(long long i=(long long)(a);i<(long long)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#include <atcoder/all>
using namespace atcoder;

long long modpow(long long a, long long n, long long mo){long long res=1;while(n>0){if(n&1){res=res*a%mo;}a=a*a%mo;n>>=1;}return res;}
long long Pow(long long a, long long n){long long res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}

const ll MOD=998244353;
const ll INF=(1ll<<60);
ll N,L;
ll ten(vl P1,vl P2){
  ll ans=0;
  vl Q2(L);
  rep(i,L) Q2[P2[i]]=i;
  vl R(L);
  rep(i,L) R[Q2[P1[i]]]=i;
  rep(i,L)rep(j,i+1,L){
    if(R[i]>R[j]) ans++;
  }
  return ans;
}
int main(){
  cin>>N>>L;
  vl C(N);
  vvl P(N+1,vl(L));
  rep(i,L) P[0][i]=i;
  rep(i,N){
    cin>>C[i];
    rep(j,L){
    cin>>P[i+1][j];
    P[i+1][j]--;
    }
  }
  vl dp(N+1,-INF);
  dp[0]=0;
  ll mat=L*(L-1)/2;
  ll nowma=-INF;
  mat=max(mat,2ll);
  rep(i,1,N+1){
    rep(j,max(0ll,i-mat),i){
      if(ten(P[j],P[i])<=i-j){
        dp[i]=max(dp[i],dp[j]+C[i-1]);
      }
    }
    if(i-mat-1>=0) nowma=max(nowma,dp[i-mat-1]);
    dp[i]=max(dp[i],nowma+C[i-1]);
  }
  ll ans=0;
  rep(i,N+1) ans=max(ans,dp[i]);
  cout<<ans<<endl;
}

Submission Info

Submission Time
Task A - Swapping Game
User number_cat
Language C++23 (GCC 15.2.0)
Score 600
Code Size 1739 Byte
Status AC
Exec Time 106 ms
Memory 6980 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 41
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt, example3.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, example0.txt, example1.txt, example2.txt, example3.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 3476 KiB
001.txt AC 11 ms 5388 KiB
002.txt AC 14 ms 5440 KiB
003.txt AC 18 ms 5516 KiB
004.txt AC 26 ms 5828 KiB
005.txt AC 49 ms 6412 KiB
006.txt AC 84 ms 6980 KiB
007.txt AC 106 ms 6864 KiB
008.txt AC 36 ms 5776 KiB
009.txt AC 64 ms 6356 KiB
010.txt AC 105 ms 6848 KiB
011.txt AC 106 ms 6868 KiB
012.txt AC 83 ms 6864 KiB
013.txt AC 104 ms 6848 KiB
014.txt AC 101 ms 6672 KiB
015.txt AC 104 ms 6920 KiB
016.txt AC 105 ms 6848 KiB
017.txt AC 106 ms 6864 KiB
018.txt AC 105 ms 6848 KiB
019.txt AC 105 ms 6924 KiB
020.txt AC 104 ms 6864 KiB
021.txt AC 105 ms 6884 KiB
022.txt AC 106 ms 6924 KiB
023.txt AC 105 ms 6800 KiB
024.txt AC 104 ms 6840 KiB
025.txt AC 104 ms 6852 KiB
026.txt AC 106 ms 6924 KiB
027.txt AC 106 ms 6864 KiB
028.txt AC 106 ms 6864 KiB
029.txt AC 105 ms 6844 KiB
030.txt AC 104 ms 6852 KiB
031.txt AC 105 ms 6800 KiB
032.txt AC 105 ms 6864 KiB
033.txt AC 104 ms 6864 KiB
034.txt AC 102 ms 6796 KiB
035.txt AC 102 ms 6860 KiB
036.txt AC 102 ms 6848 KiB
example0.txt AC 1 ms 3604 KiB
example1.txt AC 1 ms 3476 KiB
example2.txt AC 1 ms 3480 KiB
example3.txt AC 1 ms 3636 KiB