Submission #48241737


Source Code Expand

// LUOGU_RID: 138508616
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef atcoder::modint998244353 mint;

#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)

#ifdef EXODUS
	#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
	#define Debug(...) 0
#endif

//=========================================================================================================
// Something about IO

template<typename T>
void read(T &x){
	x=0;T flg=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}

//=========================================================================================================
// Define the global variables here.

bool membg=0;


constexpr int N=2e5+7;
int n,a[2][N];
ll disl[2][2][N],disr[2][2][N];
mint ans=0;

bool memed=0;

//=========================================================================================================
// Code here.

void solve(int l,int r){
	if(l>r)return;
	int mid=(l+r)>>1;
	solve(l,mid-1),solve(mid+1,r);
	disl[0][0][mid]=a[0][mid];
	disl[0][1][mid]=a[0][mid]+a[1][mid];
	disl[1][0][mid]=a[0][mid]+a[1][mid];
	disl[1][1][mid]=a[1][mid];
	for(int i=mid-1;i>=l;i--)
		for(int j=0;j<2;j++)
			disl[j][0][i]=min(disl[j][0][i+1]+a[0][i],disl[j][1][i+1]+a[0][i]+a[1][i]),
			disl[j][1][i]=min(disl[j][1][i+1]+a[1][i],disl[j][0][i+1]+a[0][i]+a[1][i]);
	disr[0][0][mid]=0;
	disr[0][1][mid]=a[1][mid];
	disr[1][0][mid]=a[0][mid];
	disr[1][1][mid]=0;
	for(int i=mid+1;i<=r;i++)
		for(int j=0;j<2;j++)
			disr[j][0][i]=min(disr[j][0][i-1]+a[0][i],disr[j][1][i-1]+a[0][i]+a[1][i]),
			disr[j][1][i]=min(disr[j][1][i-1]+a[1][i],disr[j][0][i-1]+a[0][i]+a[1][i]);
	vector<pair<ll,ll>>L,R;
	for(int i=l;i<=mid;i++)
		for(int j=0;j<2;j++)
			L.eb(disl[0][j][i],disl[1][j][i]);
	for(int i=mid;i<=r;i++)
		for(int j=0;j<2;j++)
			R.eb(disr[0][j][i],disr[1][j][i]);
	sort(L.begin(),L.end(),[&](pair<ll,ll>&lhs,pair<ll,ll>&rhs){return lhs.first-lhs.second>rhs.first-rhs.second;});
	sort(R.begin(),R.end(),[&](pair<ll,ll>&lhs,pair<ll,ll>&rhs){return lhs.first-lhs.second<rhs.first-rhs.second;});
    mint pre=0,suf=0,prec=0,sufc=0,res=0;
	for(auto [x,y]:R)suf+=y,sufc++;
	for(int i=0,j=-1;i<(int)L.size();i++){
		for(;j+1<(int)R.size()&&L[i].first-L[i].second+R[j+1].first-R[j+1].second<0;j++)
			suf-=R[j+1].second,sufc--,pre+=R[j+1].first,prec++;
		res+=L[i].first*prec+L[i].second*sufc+pre+suf;
	}
	ans+=2*res;
}

void solve(){
	read(n);
	rep(i,0,1)rep(j,1,n)read(a[i][j]);
	solve(1,n);
	for(int i=1;i<=n;i++)ans-=3ll*(a[0][i]+a[1][i]);
	printf("%d\n",ans.val());
	return;
}


//=========================================================================================================

int main(){
	Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
	int timbg=clock();
	int T=1;
	while(T--)solve();
	int timed=clock();
	Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
	fflush(stdout);
	return 0;
}

Submission Info

Submission Time
Task E - All Pair Shortest Paths
User EXODUS
Language C++ 17 (gcc 12.2)
Score 800
Code Size 3422 Byte
Status AC
Exec Time 202 ms
Memory 26660 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:20:28: warning: statement has no effect [-Wunused-value]
   20 |         #define Debug(...) 0
      |                            ^
Main.cpp:105:9: note: in expansion of macro ‘Debug’
  105 |         Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
      |         ^~~~~
Main.cpp:20:28: warning: statement has no effect [-Wunused-value]
   20 |         #define Debug(...) 0
      |                            ^
Main.cpp:110:9: note: in expansion of macro ‘Debug’
  110 |         Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
      |         ^~~~~
Main.cpp:106:13: warning: unused variable ‘timbg’ [-Wunused-variable]
  106 |         int timbg=clock();
      |             ^~~~~
Main.cpp:109:13: warning: unused variable ‘timed’ [-Wunused-variable]
  109 |         int timed=clock();
      |             ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 74
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 03_rand_1_06.txt, 03_rand_1_07.txt, 03_rand_1_08.txt, 03_rand_1_09.txt, 03_rand_1_10.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 04_rand_2_08.txt, 04_rand_2_09.txt, 04_rand_2_10.txt, 05_max_ans_01.txt, 06_rand_3_01.txt, 06_rand_3_02.txt, 06_rand_3_03.txt, 06_rand_3_04.txt, 06_rand_3_05.txt, 06_rand_3_06.txt, 06_rand_3_07.txt, 06_rand_3_08.txt, 06_rand_3_09.txt, 06_rand_3_10.txt, 07_rand_4_01.txt, 07_rand_4_02.txt, 07_rand_4_03.txt, 07_rand_4_04.txt, 07_rand_4_05.txt, 07_rand_4_06.txt, 07_rand_4_07.txt, 07_rand_4_08.txt, 07_rand_4_09.txt, 07_rand_4_10.txt, 08_rand_5_01.txt, 08_rand_5_02.txt, 08_rand_5_03.txt, 08_rand_5_04.txt, 08_rand_5_05.txt, 08_rand_5_06.txt, 08_rand_5_07.txt, 08_rand_5_08.txt, 08_rand_5_09.txt, 08_rand_5_10.txt, 09_rand_6_01.txt, 09_rand_6_02.txt, 09_rand_6_03.txt, 09_rand_6_04.txt, 09_rand_6_05.txt, 09_rand_6_06.txt, 09_rand_6_07.txt, 09_rand_6_08.txt, 09_rand_6_09.txt, 09_rand_6_10.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3748 KiB
01_sample_02.txt AC 1 ms 3788 KiB
01_sample_03.txt AC 1 ms 3792 KiB
02_small_01.txt AC 1 ms 3780 KiB
02_small_02.txt AC 1 ms 3996 KiB
02_small_03.txt AC 1 ms 3792 KiB
02_small_04.txt AC 1 ms 3788 KiB
02_small_05.txt AC 1 ms 3792 KiB
02_small_06.txt AC 1 ms 3812 KiB
02_small_07.txt AC 1 ms 3860 KiB
02_small_08.txt AC 1 ms 3928 KiB
02_small_09.txt AC 1 ms 3928 KiB
02_small_10.txt AC 1 ms 3904 KiB
03_rand_1_01.txt AC 177 ms 26432 KiB
03_rand_1_02.txt AC 174 ms 26544 KiB
03_rand_1_03.txt AC 174 ms 26444 KiB
03_rand_1_04.txt AC 175 ms 26656 KiB
03_rand_1_05.txt AC 174 ms 26556 KiB
03_rand_1_06.txt AC 175 ms 26420 KiB
03_rand_1_07.txt AC 176 ms 26432 KiB
03_rand_1_08.txt AC 175 ms 26468 KiB
03_rand_1_09.txt AC 176 ms 26568 KiB
03_rand_1_10.txt AC 174 ms 26448 KiB
04_rand_2_01.txt AC 169 ms 26660 KiB
04_rand_2_02.txt AC 171 ms 26408 KiB
04_rand_2_03.txt AC 169 ms 26372 KiB
04_rand_2_04.txt AC 169 ms 26400 KiB
04_rand_2_05.txt AC 169 ms 26400 KiB
04_rand_2_06.txt AC 168 ms 26492 KiB
04_rand_2_07.txt AC 169 ms 26376 KiB
04_rand_2_08.txt AC 173 ms 26444 KiB
04_rand_2_09.txt AC 169 ms 26488 KiB
04_rand_2_10.txt AC 169 ms 26656 KiB
05_max_ans_01.txt AC 167 ms 26444 KiB
06_rand_3_01.txt AC 190 ms 26424 KiB
06_rand_3_02.txt AC 190 ms 26408 KiB
06_rand_3_03.txt AC 192 ms 26416 KiB
06_rand_3_04.txt AC 190 ms 26400 KiB
06_rand_3_05.txt AC 189 ms 26468 KiB
06_rand_3_06.txt AC 189 ms 26492 KiB
06_rand_3_07.txt AC 190 ms 26408 KiB
06_rand_3_08.txt AC 202 ms 26572 KiB
06_rand_3_09.txt AC 192 ms 26472 KiB
06_rand_3_10.txt AC 202 ms 26488 KiB
07_rand_4_01.txt AC 200 ms 26484 KiB
07_rand_4_02.txt AC 202 ms 26572 KiB
07_rand_4_03.txt AC 200 ms 26492 KiB
07_rand_4_04.txt AC 201 ms 26376 KiB
07_rand_4_05.txt AC 200 ms 26416 KiB
07_rand_4_06.txt AC 200 ms 26428 KiB
07_rand_4_07.txt AC 200 ms 26572 KiB
07_rand_4_08.txt AC 200 ms 26496 KiB
07_rand_4_09.txt AC 199 ms 26428 KiB
07_rand_4_10.txt AC 200 ms 26492 KiB
08_rand_5_01.txt AC 200 ms 26420 KiB
08_rand_5_02.txt AC 199 ms 26448 KiB
08_rand_5_03.txt AC 199 ms 26572 KiB
08_rand_5_04.txt AC 187 ms 26400 KiB
08_rand_5_05.txt AC 196 ms 26484 KiB
08_rand_5_06.txt AC 200 ms 26444 KiB
08_rand_5_07.txt AC 193 ms 26408 KiB
08_rand_5_08.txt AC 184 ms 26428 KiB
08_rand_5_09.txt AC 192 ms 26496 KiB
08_rand_5_10.txt AC 183 ms 26416 KiB
09_rand_6_01.txt AC 197 ms 26656 KiB
09_rand_6_02.txt AC 195 ms 26556 KiB
09_rand_6_03.txt AC 195 ms 26432 KiB
09_rand_6_04.txt AC 189 ms 26444 KiB
09_rand_6_05.txt AC 189 ms 26432 KiB
09_rand_6_06.txt AC 189 ms 26572 KiB
09_rand_6_07.txt AC 188 ms 26656 KiB
09_rand_6_08.txt AC 189 ms 26480 KiB
09_rand_6_09.txt AC 189 ms 26520 KiB
09_rand_6_10.txt AC 192 ms 26372 KiB