QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#492547#163. Change a PasswordAfterlife#AC ✓27ms3820kbC++20903b2024-07-26 13:31:462024-07-26 13:31:46

Judging History

This is the latest submission verdict.

  • [2024-07-26 13:31:46]
  • Judged
  • Verdict: AC
  • Time: 27ms
  • Memory: 3820kb
  • [2024-07-26 13:31:46]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
string s;
typedef long long ll;
ll mn = 0;
ll cur = 0;
ll ans;
void output(ll x,int len) {
    if(!len) return ;
    output(x / 10 , len - 1) ;
    cout << (x % 10);
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0);
    cin >> s;
    ll v = 0;
    for(auto x : s) v = v * 10 + x - '0';

    vector<int> p(10);
    for(int i = 0;i < 10;i++) p[i] =i;
    ll mx = 1;
    for(int i = 0;i < s.size();i++) mx *= 10;
    do{
        ll cur = 0;
        for(int i = 0;i < s.size();i++) cur = cur * 10 + p[i];
        ll dif = min(abs(cur - v) , mx - abs(cur - v));
        if(dif > mn) {
            mn = dif ; 
            ans = cur;
        }
        else if(dif == mn) {
            ans = min(ans, cur);
        }
    }while(next_permutation(p.begin() ,p.end()));
    output(ans , s.size()); cout << '\n';return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 3608kb

input:

201

output:

701

result:

ok single line: '701'

Test #2:

score: 0
Accepted
time: 11ms
memory: 3584kb

input:

512

output:

012

result:

ok single line: '012'

Test #3:

score: 0
Accepted
time: 20ms
memory: 3480kb

input:

99999

output:

49876

result:

ok single line: '49876'

Test #4:

score: 0
Accepted
time: 24ms
memory: 3516kb

input:

765876346

output:

265874931

result:

ok single line: '265874931'

Test #5:

score: 0
Accepted
time: 27ms
memory: 3520kb

input:

15526126

output:

65498732

result:

ok single line: '65498732'

Test #6:

score: 0
Accepted
time: 26ms
memory: 3604kb

input:

596140804

output:

096142357

result:

ok single line: '096142357'

Test #7:

score: 0
Accepted
time: 23ms
memory: 3584kb

input:

12159688

output:

62159703

result:

ok single line: '62159703'

Test #8:

score: 0
Accepted
time: 22ms
memory: 3608kb

input:

259516

output:

759486

result:

ok single line: '759486'

Test #9:

score: 0
Accepted
time: 19ms
memory: 3548kb

input:

646368

output:

146370

result:

ok single line: '146370'

Test #10:

score: 0
Accepted
time: 22ms
memory: 3616kb

input:

901017

output:

401235

result:

ok single line: '401235'

Test #11:

score: 0
Accepted
time: 23ms
memory: 3612kb

input:

390529

output:

890527

result:

ok single line: '890527'

Test #12:

score: 0
Accepted
time: 26ms
memory: 3476kb

input:

5964700

output:

0964712

result:

ok single line: '0964712'

Test #13:

score: 0
Accepted
time: 27ms
memory: 3596kb

input:

32352460

output:

82351976

result:

ok single line: '82351976'

Test #14:

score: 0
Accepted
time: 25ms
memory: 3524kb

input:

4903140382

output:

9876543210

result:

ok single line: '9876543210'

Test #15:

score: 0
Accepted
time: 14ms
memory: 3520kb

input:

23

output:

73

result:

ok single line: '73'

Test #16:

score: 0
Accepted
time: 11ms
memory: 3584kb

input:

91

output:

41

result:

ok single line: '41'

Test #17:

score: 0
Accepted
time: 22ms
memory: 3780kb

input:

713125

output:

213098

result:

ok single line: '213098'

Test #18:

score: 0
Accepted
time: 24ms
memory: 3524kb

input:

521131794

output:

021345678

result:

ok single line: '021345678'

Test #19:

score: 0
Accepted
time: 16ms
memory: 3820kb

input:

974

output:

473

result:

ok single line: '473'

Test #20:

score: 0
Accepted
time: 26ms
memory: 3544kb

input:

6941738

output:

1942035

result:

ok single line: '1942035'

Test #21:

score: 0
Accepted
time: 14ms
memory: 3616kb

input:

41

output:

91

result:

ok single line: '91'

Test #22:

score: 0
Accepted
time: 26ms
memory: 3516kb

input:

56124627

output:

06124598

result:

ok single line: '06124598'

Test #23:

score: 0
Accepted
time: 18ms
memory: 3764kb

input:

1488

output:

6487

result:

ok single line: '6487'

Test #24:

score: 0
Accepted
time: 23ms
memory: 3480kb

input:

197136

output:

697135

result:

ok single line: '697135'

Test #25:

score: 0
Accepted
time: 14ms
memory: 3584kb

input:

60

output:

10

result:

ok single line: '10'

Test #26:

score: 0
Accepted
time: 17ms
memory: 3612kb

input:

2026

output:

7026

result:

ok single line: '7026'

Test #27:

score: 0
Accepted
time: 26ms
memory: 3592kb

input:

9523001179

output:

4523016789

result:

ok single line: '4523016789'

Test #28:

score: 0
Accepted
time: 14ms
memory: 3524kb

input:

7927

output:

2930

result:

ok single line: '2930'

Test #29:

score: 0
Accepted
time: 10ms
memory: 3596kb

input:

89

output:

39

result:

ok single line: '39'

Test #30:

score: 0
Accepted
time: 27ms
memory: 3520kb

input:

39248928

output:

89250134

result:

ok single line: '89250134'

Test #31:

score: 0
Accepted
time: 26ms
memory: 3764kb

input:

9448588101

output:

4398765210

result:

ok single line: '4398765210'

Test #32:

score: 0
Accepted
time: 14ms
memory: 3548kb

input:

9

output:

4

result:

ok single line: '4'

Test #33:

score: 0
Accepted
time: 26ms
memory: 3604kb

input:

68652768

output:

18652749

result:

ok single line: '18652749'

Test #34:

score: 0
Accepted
time: 25ms
memory: 3744kb

input:

8958581316

output:

3958601247

result:

ok single line: '3958601247'

Test #35:

score: 0
Accepted
time: 27ms
memory: 3608kb

input:

1757768

output:

6758012

result:

ok single line: '6758012'

Test #36:

score: 0
Accepted
time: 25ms
memory: 3592kb

input:

5171863951

output:

0172345689

result:

ok single line: '0172345689'

Test #37:

score: 0
Accepted
time: 19ms
memory: 3548kb

input:

86283

output:

36284

result:

ok single line: '36284'

Test #38:

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

input:

054

output:

549

result:

ok single line: '549'

Test #39:

score: 0
Accepted
time: 27ms
memory: 3612kb

input:

10134233

output:

60134257

result:

ok single line: '60134257'

Test #40:

score: 0
Accepted
time: 15ms
memory: 3612kb

input:

746

output:

246

result:

ok single line: '246'

Test #41:

score: 0
Accepted
time: 21ms
memory: 3532kb

input:

6599320

output:

1598764

result:

ok single line: '1598764'

Test #42:

score: 0
Accepted
time: 19ms
memory: 3744kb

input:

65071

output:

15072

result:

ok single line: '15072'

Test #43:

score: 0
Accepted
time: 14ms
memory: 3580kb

input:

63

output:

13

result:

ok single line: '13'

Test #44:

score: 0
Accepted
time: 26ms
memory: 3592kb

input:

1920905

output:

6920875

result:

ok single line: '6920875'

Test #45:

score: 0
Accepted
time: 25ms
memory: 3532kb

input:

3177662539

output:

8176954320

result:

ok single line: '8176954320'

Test #46:

score: 0
Accepted
time: 26ms
memory: 3612kb

input:

7848458

output:

2847965

result:

ok single line: '2847965'

Test #47:

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

input:

072

output:

572

result:

ok single line: '572'

Test #48:

score: 0
Accepted
time: 21ms
memory: 3612kb

input:

3484901367

output:

8490123567

result:

ok single line: '8490123567'

Test #49:

score: 0
Accepted
time: 25ms
memory: 3552kb

input:

7215285

output:

2198765

result:

ok single line: '2198765'

Test #50:

score: 0
Accepted
time: 18ms
memory: 3616kb

input:

36323

output:

86324

result:

ok single line: '86324'

Test #51:

score: 0
Accepted
time: 25ms
memory: 3616kb

input:

5861875

output:

0861923

result:

ok single line: '0861923'

Test #52:

score: 0
Accepted
time: 24ms
memory: 3604kb

input:

488771862

output:

987654321

result:

ok single line: '987654321'

Test #53:

score: 0
Accepted
time: 18ms
memory: 3604kb

input:

1348

output:

6348

result:

ok single line: '6348'

Test #54:

score: 0
Accepted
time: 19ms
memory: 3600kb

input:

76327

output:

26319

result:

ok single line: '26319'

Test #55:

score: 0
Accepted
time: 22ms
memory: 3616kb

input:

9999999999

output:

4987653210

result:

ok single line: '4987653210'

Test #56:

score: 0
Accepted
time: 26ms
memory: 3740kb

input:

0000000000

output:

5012346789

result:

ok single line: '5012346789'

Test #57:

score: 0
Accepted
time: 26ms
memory: 3584kb

input:

1111111111

output:

6109875432

result:

ok single line: '6109875432'

Test #58:

score: 0
Accepted
time: 26ms
memory: 3480kb

input:

1115110610

output:

6109875432

result:

ok single line: '6109875432'

Test #59:

score: 0
Accepted
time: 25ms
memory: 3520kb

input:

1115110611

output:

6120345789

result:

ok single line: '6120345789'

Test #60:

score: 0
Accepted
time: 26ms
memory: 3584kb

input:

1109875427

output:

6109875423

result:

ok single line: '6109875423'

Test #61:

score: 0
Accepted
time: 25ms
memory: 3584kb

input:

1109875428

output:

6109875432

result:

ok single line: '6109875432'