UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214529#574. t3lqw0318ms3688kbC++1.3kb2024-11-19 20:54:372024-11-19 23:02:23

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e5+10;
int a[N],b[N],c[N];
int n,Z,X,Y,ans;
void solve(int i,bool vis[]){
    if(vis[i])return;
    //cout<<c[i]<<'\n';
    vis[i]=1;
    int j=1;
    while(j<=max(i,n-i-1)&&c[i]>0&&Z*j<X+Y){
        if(j<=n-i-1&&c[j+i]<0){
            int cc=min(-c[j+i],c[i]);
            ans+=Z*j*cc;
            c[i]-=cc;
            c[j+i]+=cc;
            vis[i+j]=1;
        }
        if(j<=i&&c[i-j]<0){
            int cc=min(-c[i-j],c[i]);
            ans+=Z*j*cc;
            c[i]-=cc;
            c[i-j]+=cc;
            vis[i-j]=1;
        }
        if(j<=n-i-1&&c[j+i]==0){
            solve(i+j,vis);
        }
        if(j<=i&&c[i-j]==0){
            solve(i-j,vis);
        }
        j++;
    }
    vis[i]=0;
    return;
}
bool tvis[N];
signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>X>>Y>>Z;
    int S=X+Y;
    for (int i = 0; i < n; i ++ ){
        cin>>a[i]>>b[i];
        c[i]=a[i]-b[i];
    }
    for (int i = 0; i < n; i ++ ) solve(i,tvis);
    //cout<<ans;
    for (int i = 0; i < n; i ++ ){
        if(c[i]<0)ans+=X*(-c[i])//,cout<<c[i];
        ;
        if(c[i]>0)ans+=Y*c[i]//,cout<<c[i];
        ;
        //cout<<' ';
    }
    cout<<ans;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1264kb

input:

50 4 401 83
1 9
0 10
1 1
7 5
6 2
6 10
5 10
5 5
4 4
10 8
8 3
4 8
8 0
1 2
8 9
9 9
4 6
8 7
3 10
2 4
9 3...

output:

15420

result:

wrong answer 1st words differ - expected: '12399', found: '15420'

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

100000 100000000 100000000 1
4 1
7 1
7 6
7 5
7 5
6 6
5 1
1 4
2 0
3 0
5 7
1 9
1 1
6 8
2 5
7 7
7 9
6 3...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 318ms
memory: 3688kb

input:

100000 30694440 93757838 144
1 4
0 5
9 3
3 8
6 9
7 4
3 5
6 1
6 6
4 5
10 0
9 4
7 4
9 1
5 4
8 4
2 0
10...

output:

17454550992

result:

wrong answer 1st words differ - expected: '11782941072', found: '17454550992'