#include<bits/stdc++.h>
//#include "prison.h"
#pragma GCC optimize ("O3")
using namespace std;
#define el "\n"
#define se " "
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
const ll INF=1e18,ch=1e18;
ll a,b,c,d,n,COST,t,last,ab,ba,n1,n2,fl1,fl2,o1,o2,flag,flag1,flag2,g,m,m1,m2,i,j,lr,f,k,l,r,y,o,p,mx=-ch,mx1=-ch,mx2=-ch,q,q1,q2,q3,q4,mn=ch,mn1=ch,mn2=ch,f1,f2,f3,pos,ans,sum,sz=1,MOD=1e9+7,zero=0,a1,b1,c1,val,sum1,cur,res,ans1,res1,kk,kkk,cnt,cnt1,fl;
pair < ll , pair < ll , ll > > A[300005];
ll B[4][300005];
pair < ll , ll > C[300005][3];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W)
{
n=N;k=M;
for(i=1;i<=k;i++)
{
A[i].ff=X[i-1]+1;
A[i].ss.ff=Y[i-1]+1;
if (A[i].ss.ff==1) flag++;
A[i].ss.ss=W[i-1];
if (A[i].ff%2!=0) q1++;
if (A[i].ff<=2) q2++;
}
if (q1==k)
{
for(i=1;i<=k;i++)
{
f+=A[i].ss.ss;
}
return f;
}
if (flag==k)
{
ll dp[300005][3]={0};
ll C[300005]={0};
for(i=1;i<=k;i++)
{
C[A[i].ff]=A[i].ss.ss;
}
dp[1][0]=0;
dp[1][1]=C[2];
for(i=2;i<=n;i++)
{
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
dp[i][1]=max({dp[i-1][1]-C[i],dp[i-2][1],dp[i-2][0]+C[i-1]})+C[i+1];
}
return max(dp[n][0],dp[n][1]);
}
else
{
for(i=1;i<=k;i++)
{
j=A[i].ff;
if (C[j][1].ff==0) {C[j][1].ff=A[i].ss.ss;C[j][2].ff=A[i].ss.ff;}
else {C[j][1].ss=A[i].ss.ss;C[j][2].ss=A[i].ss.ff;}
}
for(i=1;i<=n;i++)
{
a=C[i][2].ff;b=C[i][2].ss;
if (a==0) continue;
if (b==0)
{
f+=C[i][1].ff;
continue;
}
if (a>b) swap(a,b);
if ((a+1!=b)||(a!=1&&b!=n))
{
f+=C[i][1].ff;
f+=C[i][1].ss;
continue;
}
else
{
f+=max(C[i][1].ff,C[i][1].ss);
}
}
return f;
}
}
//int main()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// cin>>n>>a>>b;
// vector < vector < int > > v=devise_strategy(a,b);
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
13388 KB |
Output is correct |
2 |
Correct |
32 ms |
14308 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
94 ms |
23660 KB |
Output is correct |
6 |
Correct |
93 ms |
23672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
53 ms |
17328 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '1493600517' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
20 ms |
12220 KB |
Output is correct |
4 |
Correct |
17 ms |
11380 KB |
Output is correct |
5 |
Correct |
34 ms |
14420 KB |
Output is correct |
6 |
Correct |
27 ms |
14296 KB |
Output is correct |
7 |
Correct |
36 ms |
14272 KB |
Output is correct |
8 |
Correct |
39 ms |
14420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
20 ms |
12220 KB |
Output is correct |
4 |
Correct |
17 ms |
11380 KB |
Output is correct |
5 |
Correct |
34 ms |
14420 KB |
Output is correct |
6 |
Correct |
27 ms |
14296 KB |
Output is correct |
7 |
Correct |
36 ms |
14272 KB |
Output is correct |
8 |
Correct |
39 ms |
14420 KB |
Output is correct |
9 |
Correct |
32 ms |
19032 KB |
Output is correct |
10 |
Incorrect |
33 ms |
16652 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '33302362838090' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
13388 KB |
Output is correct |
2 |
Correct |
32 ms |
14308 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
94 ms |
23660 KB |
Output is correct |
6 |
Correct |
93 ms |
23672 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Incorrect |
53 ms |
17328 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '1493600517' |
9 |
Halted |
0 ms |
0 KB |
- |