Submission #577737


Source Code Expand

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define int ll

int to_i(const string &s) {
    int ret;
    stringstream ss;
    ss<<s;
    ss>>ret;
    return ret;
}

string in,ans;

int f(string &s) {
    int t1=to_i(in);
    int t2=to_i(s);
    int p=pow(10.0,in.size());
    int t=min(abs(t1-t2),p-abs(t1-t2));

    return t;
}

void update(string &s) {
    if(ans=="") {
        ans=s;
        return;
    }
    int t1=f(s);
    int t2=f(ans);
    if(t2<t1) ans=s;
}

void dfs(string s,int S) {
    if(s.size()==in.size()) {
        update(s);
    }
    rep(i,10) {
        if(S>>i&1) continue;
        dfs(s+string(1,i+'0'),S|1<<i);
    }
}

signed main() {
    cin>>in;
    string s;
    int t=in[0]-'0';
    if(t<5) {
        t+=5;
    }
    else {
        t-=5;
    }
    s+=string(1,t+'0');
    dfs(s,1<<t);
    s="";
    t=in[0]-'0';
    if(t<6) {
        t+=4;
    }
    else {
        t-=6;
    }
    s+=string(1,t+'0');
    dfs(s,1<<t);
    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task B - Change a Password
User MOTA
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1261 Byte
Status AC
Exec Time 4473 ms
Memory 1152 KiB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 61
Set Name Test Cases
All 00_test_00, 00_test_01, 00_test_02, 00_test_03, 01_rand_00, 01_rand_01, 01_rand_02, 01_rand_03, 01_rand_04, 01_rand_05, 01_rand_06, 01_rand_07, 01_rand_08, 01_rand_09, 01_rand_10, 01_rand_11, 01_rand_12, 01_rand_13, 01_rand_14, 01_rand_15, 01_rand_16, 01_rand_17, 01_rand_18, 01_rand_19, 01_rand_20, 01_rand_21, 01_rand_22, 01_rand_23, 01_rand_24, 01_rand_25, 01_rand_26, 01_rand_27, 01_rand_28, 01_rand_29, 01_rand_30, 01_rand_31, 01_rand_32, 01_rand_33, 01_rand_34, 01_rand_35, 01_rand_36, 01_rand_37, 01_rand_38, 01_rand_39, 01_rand_40, 01_rand_41, 01_rand_42, 01_rand_43, 01_rand_44, 01_rand_45, 01_rand_46, 01_rand_47, 01_rand_48, 01_rand_49, 99_handmake_00, 99_handmake_01, 99_handmake_02, 99_handmake_03, 99_handmake_04, 99_handmake_05, 99_handmake_06
Case Name Status Exec Time Memory
00_test_00 AC 451 ms 1044 KiB
00_test_01 AC 449 ms 1044 KiB
00_test_02 AC 484 ms 1036 KiB
00_test_03 AC 4199 ms 960 KiB
01_rand_00 AC 2311 ms 1144 KiB
01_rand_01 AC 4322 ms 1044 KiB
01_rand_02 AC 2493 ms 960 KiB
01_rand_03 AC 613 ms 972 KiB
01_rand_04 AC 624 ms 1068 KiB
01_rand_05 AC 611 ms 1148 KiB
01_rand_06 AC 612 ms 980 KiB
01_rand_07 AC 1062 ms 952 KiB
01_rand_08 AC 2429 ms 1152 KiB
01_rand_09 AC 4097 ms 976 KiB
01_rand_10 AC 469 ms 964 KiB
01_rand_11 AC 447 ms 980 KiB
01_rand_12 AC 606 ms 980 KiB
01_rand_13 AC 4320 ms 1036 KiB
01_rand_14 AC 451 ms 1140 KiB
01_rand_15 AC 1048 ms 1016 KiB
01_rand_16 AC 450 ms 1144 KiB
01_rand_17 AC 2390 ms 980 KiB
01_rand_18 AC 449 ms 984 KiB
01_rand_19 AC 623 ms 980 KiB
01_rand_20 AC 448 ms 1148 KiB
01_rand_21 AC 452 ms 1012 KiB
01_rand_22 AC 4473 ms 980 KiB
01_rand_23 AC 460 ms 1144 KiB
01_rand_24 AC 444 ms 956 KiB
01_rand_25 AC 2374 ms 1144 KiB
01_rand_26 AC 4067 ms 980 KiB
01_rand_27 AC 448 ms 1108 KiB
01_rand_28 AC 2383 ms 1136 KiB
01_rand_29 AC 4068 ms 1108 KiB
01_rand_30 AC 1054 ms 1044 KiB
01_rand_31 AC 4099 ms 1140 KiB
01_rand_32 AC 484 ms 972 KiB
01_rand_33 AC 449 ms 988 KiB
01_rand_34 AC 2279 ms 980 KiB
01_rand_35 AC 452 ms 1036 KiB
01_rand_36 AC 1090 ms 1036 KiB
01_rand_37 AC 478 ms 1020 KiB
01_rand_38 AC 448 ms 1024 KiB
01_rand_39 AC 1044 ms 960 KiB
01_rand_40 AC 4302 ms 1144 KiB
01_rand_41 AC 1090 ms 1032 KiB
01_rand_42 AC 447 ms 984 KiB
01_rand_43 AC 4090 ms 980 KiB
01_rand_44 AC 1053 ms 1144 KiB
01_rand_45 AC 474 ms 984 KiB
01_rand_46 AC 1060 ms 984 KiB
01_rand_47 AC 4085 ms 1148 KiB
01_rand_48 AC 450 ms 1148 KiB
01_rand_49 AC 473 ms 1148 KiB
99_handmake_00 AC 4110 ms 984 KiB
99_handmake_01 AC 4217 ms 1020 KiB
99_handmake_02 AC 4242 ms 968 KiB
99_handmake_03 AC 4257 ms 980 KiB
99_handmake_04 AC 4430 ms 1064 KiB
99_handmake_05 AC 4157 ms 1140 KiB
99_handmake_06 AC 4326 ms 1144 KiB