QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#336981#6621. Luggage LockHJRWA 56ms3824kbC++2311.0kb2024-02-25 00:24:102024-02-25 00:24:11

Judging History

你现在查看的是最新测评结果

  • [2024-02-25 00:24:11]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:3824kb
  • [2024-02-25 00:24:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout<<#x<<": "<<x<<endl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll=long long;
using ull=unsigned long long;
#define int long long
int cur=0;
void solve(){
    cur++;
    string aa,bb;
    cin>>aa>>bb;
    if(cur==73){
        cout<<aa<<endl<<bb<<endl;
    }
    vector<int> a,b;
    for(int i=0;i<4;i++)
        a.push_back(aa[i]-'0');
    for(int i=0;i<4;i++)
        b.push_back(bb[i]-'0');
    int res=0x3f3f3f3f;
    int cnt=0;
    //******************************
    {
    vector<int> u(4),dow(4);
    for(int i=0;i<4;i++){
        if(a[i]<=b[i])
            u[i]=b[i]-a[i];
        else
            u[i]=b[i]+10-a[i];
    }
    for(int i=0;i<4;i++){
        if(a[i]>b[i])
            dow[i]=a[i]-b[i];
        else
            dow[i]=a[i]+10-b[i];
    }
    int rr=0;
    for(int i=0;i<4;i++)//1 2 3 4
        rr+=min(u[i],dow[i]);
    res=min(res,rr);
    int cct=0;
    vector<int> up=u,down=dow;
    while(1){//1234
        int mi=0x3f3f3f3f;
        for(int i=0;i<4;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct);
            break;
        }
    }
    up=u,down=dow;
    cct=0;
    while(1){//1234
        int mi=0x3f3f3f3f;
        for(int i=0;i<4;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct);
            break;
        }
    }

    cct=0;
    up=u,down=dow;
    while(1){//123
        int mi=0x3f3f3f3f;
        for(int i=0;i<3;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<3;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[3],down[3]));
            break;
        }
    }

    cct=0;
    up=u,down=dow;
    while(1){//123
        int mi=0x3f3f3f3f;
        for(int i=0;i<3;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<3;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[3],down[3]));
            break;
        }
    }    

    cct=0;
    up=u,down=dow;
    while(1){//234
        int mi=0x3f3f3f3f;
        for(int i=1;i<4;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[0],down[0]));
            break;
        }
    }
    cct=0;
    up=u,down=dow;
    while(1){//234
        int mi=0x3f3f3f3f;
        for(int i=1;i<4;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[0],down[0]));
            break;
        }
    } 
    // debug(res);
    up=u,down=dow;
    //12 34
    res=min(res,min(max(up[0],up[1]),max(down[0],down[1]))+min(max(up[2],up[3]),max(down[2],down[3])));
    // 12 3 4
    res=min(res,min(max(up[0],up[1]),max(down[0],down[1]))+min(up[2],down[2])+min(up[3],down[3]));
    // 1 2 34
    res=min(res,min(max(up[2],up[3]),max(down[2],down[3]))+min(up[0],down[0])+min(up[1],down[1]));
    // 1 23 4
    res=min(res,min(max(up[1],up[2]),max(down[1],down[2]))+min(up[0],down[0])+min(up[3],down[3]));
    }
    //******************************
    {
    vector<int> u(4),dow(4);
    for(int i=0;i<4;i++){
        if(a[i]<b[i])
            u[i]=b[i]-a[i];
        else
            u[i]=b[i]+10-a[i];
    }
    for(int i=0;i<4;i++){
        if(a[i]>=b[i])
            dow[i]=a[i]-b[i];
        else
            dow[i]=a[i]+10-b[i];
    }
    int rr=0;
    for(int i=0;i<4;i++)//1 2 3 4
        rr+=min(u[i],dow[i]);
    res=min(res,rr);
    int cct=0;
    vector<int> up=u,down=dow;
    while(1){//1234
        int mi=0x3f3f3f3f;
        for(int i=0;i<4;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct);
            break;
        }
    }
    up=u,down=dow;
    cct=0;
    while(1){//1234
        int mi=0x3f3f3f3f;
        for(int i=0;i<4;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct);
            break;
        }
    }

    cct=0;
    up=u,down=dow;
    while(1){//123
        int mi=0x3f3f3f3f;
        for(int i=0;i<3;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<3;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[3],down[3]));
            break;
        }
    }

    cct=0;
    up=u,down=dow;
    while(1){//123
        int mi=0x3f3f3f3f;
        for(int i=0;i<3;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<3;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[3],down[3]));
            break;
        }
    }    

    cct=0;
    up=u,down=dow;
    while(1){//234
        int mi=0x3f3f3f3f;
        for(int i=1;i<4;i++){
            if(up[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(up[j]==0)
                        break;
                    mi=min(mi,up[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    up[k]-=mi;
                    up[k]=max(up[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[0],down[0]));
            break;
        }
    }
    cct=0;
    up=u,down=dow;
    while(1){//234
        int mi=0x3f3f3f3f;
        for(int i=1;i<4;i++){
            if(down[i]!=0){
                int j=i;
                for(;j<4;j++){
                    if(down[j]==0)
                        break;
                    mi=min(mi,down[j]);
                }
                if(mi==0x3f3f3f3f)
                    break;
                cct+=mi;
                for(int k=i;k<j;k++){
                    down[k]-=mi;
                    down[k]=max(down[k],0ll);
                }
                break;
            }
        }
        if(mi==0x3f3f3f3f){
            res=min(res,cct+min(up[0],down[0]));
            break;
        }
    } 
    // debug(res);
    up=u,down=dow;
    //12 34
    res=min(res,min(max(up[0],up[1]),max(down[0],down[1]))+min(max(up[2],up[3]),max(down[2],down[3])));
    // 12 3 4
    res=min(res,min(max(up[0],up[1]),max(down[0],down[1]))+min(up[2],down[2])+min(up[3],down[3]));
    // 1 2 34
    res=min(res,min(max(up[2],up[3]),max(down[2],down[3]))+min(up[0],down[0])+min(up[1],down[1]));
    // 1 23 4
    res=min(res,min(max(up[1],up[2]),max(down[1],down[2]))+min(up[0],down[0])+min(up[3],down[3]));
    }

    cout<<res<<endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

input:

6
1234 2345
1234 0123
1234 2267
1234 3401
1234 1344
1234 2468

output:

1
1
4
5
1
4

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 56ms
memory: 3536kb

input:

100000
9138 9251
0887 4577
2745 6294
6883 1197
8654 2502
7867 7941
7505 2717
1497 7726
3337 8042
2767 8782
5311 4368
9711 6229
7105 8101
3553 6673
6544 7940
8848 8920
1458 6315
4605 2931
5505 7310
5963 4765
7625 0418
4049 0136
2078 6899
3339 1080
2276 6814
4249 4182
1861 0824
8975 8926
6447 6965
226...

output:

3
6
6
8
9
7
6
7
10
9
6
8
5
4
8
5
8
7
9
4
8
8
8
6
8
5
7
5
7
5
7
7
6
8
4
10
6
5
6
7
7
7
4
7
8
6
5
9
7
6
7
11
10
10
7
5
6
5
7
6
7
9
5
5
6
6
8
5
7
9
10
6
3924
8998
10
5
6
7
6
6
8
6
8
7
7
8
7
8
6
7
6
5
5
6
6
5
7
5
9
6
7
7
7
9
6
9
5
5
8
10
7
3
5
6
7
9
8
6
6
7
10
5
5
6
9
8
6
8
6
5
7
6
11
5
9
6
7
5
10
7
5
8...

result:

wrong answer 73rd numbers differ - expected: '10', found: '3924'