QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#582459#6621. Luggage Lockgates_orzWA 38ms3628kbC++173.3kb2024-09-22 16:30:502024-09-22 16:30:56

Judging History

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

  • [2024-09-22 16:30:56]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:3628kb
  • [2024-09-22 16:30:50]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

typedef long long LL;
#define int LL
#define inl inline
const int N = 3e5 + 10;
const int M = N * 2;
//const int mod=998244353;
const int mod = 1000000007;
const double eps = 1e-8;
//const int mod=1e9+7;
typedef pair<int,int> PII;
//const int INF=0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m;

void become_faster() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

vector<int>add(5),del(5);
int fun(int a[]) {
    int res=0;
    int tadd[5],tdel[5];
    for(int i=1;i<=4;i++)tadd[i]=add[i],tdel[i]=del[i];
    int sign=1;
    for(int i=1;i<=4;i++) {
        if(a[i]!=1)sign=0;
    }
    //if(sign==1)cout<<"res="<<res<<endl;
    /*if(sign) {
        cout<<"add: ";
        for(int i=1;i<=4;i++)cout<<tadd[i]<<" ";cout<<endl;
    }*/
    for(int i=1;i<=4;i++) {

        int dd[5]={0,0,0,0,0};
        if(a[i]==1) {
            res+=tadd[i];
            dd[i]=tadd[i];
            for(int j=i+1;j<=4;j++) {
                if(a[j]==1) {
                    dd[j]=min(tadd[j],dd[j-1]);
                    //tadd[j]-=min(tadd[j],tadd[j-1]);
                }
                else break;
            }
            for(int j=i+1;j<=4;j++) {
                if(a[j]==1)tadd[j]-=dd[j];
                else break;
            }
            tadd[i]=0;
        }
        else {
            res+=tdel[i];
            dd[i]=tdel[i];
            for(int j=i+1;j<=4;j++) {
                if(a[j]==-1) {
                    dd[j]=min(dd[j-1],tdel[j]);
                    //tdel[j]-=min(tdel[j-1],tdel[j]);
                }
                else break;
            }
            for(int j=i+1;j<=4;j++) {
                if(a[j]==-1) {
                    tdel[j]-=dd[j];
                }
                else break;
            }
            tdel[i]=0;
        }
        /*if(sign) {
            cout<<"add: ";
            for(int j=1;j<=4;j++)cout<<tadd[j]<<" ";cout<<endl;
        }*/
        /*if(sign) {
            cout << "add: ";
            for (int j = 1; j <= 4; j++)cout << tadd[j] << " ";
            cout << endl;
        }*/

    }

    /*if(res==2) {
        cout<<"a: ";
        for(int i=1;i<=4;i++)cout<<a[i]<<" ";cout<<endl;
    }*/
    return res;
}
void solve() {
    string s1,s2;
    cin>>s1>>s2;
    n=4;
    for(int i=0;i<4;i++) {
        int x=s1[i]-s2[i];
        if(x==0) {
            add[i+1]=del[i+1]=0;
        }
        else {
            if(x<0) {
                add[i+1]=-x;
                del[i+1]=x+10;
            }
            else {
                del[i+1]=x;
                add[i+1]=10-x;
            }
        }
    }
    //for(int i=1;i<=4;i++)cout<<add[i]<<" "<<del[i]<<endl;
    int res=100;
    int a[5];
    auto dfs=[&](auto &self,int p)->void {
        if(p>4) {
            //for(int i=1;i<=4;i++)cout<<a[i]<<" ";cout<<endl;
            res=min(res,fun(a));
            return;
        }
        a[p]=1;
        self(self,p+1);
        a[p]=-1;
        self(self,p+1);
    };
    dfs(dfs,1);
    cout<<res<<"\n";

}

signed main() {
    become_faster();
    int T = 1;
    //T=read();
    cin>>T;
    //for(int i=1;i<=100;i++)solve(i);
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

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: 38ms
memory: 3628kb

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
11
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
9
8
7
7
7...

result:

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