QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59717#1361. Ant TypingBeevo#TL 5ms3524kbC++23810b2022-10-31 21:57:412022-10-31 21:57:43

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-31 21:57:43]
  • Judged
  • Verdict: TL
  • Time: 5ms
  • Memory: 3524kb
  • [2022-10-31 21:57:41]
  • Submitted

answer

#include <bits/stdc++.h>

#define el '\n'
#define ll long long
#define ld long double

#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int solve(string &s, string &t) {
    int ret = 0;

    int p[10];

    for (int i = 0; i < 9; i++)
        p[t[i] - '0'] = i;

    int lst = 0;

    for (auto &i: s)
        ret += abs(lst - p[i - '0']), lst = p[i - '0'];

    return ret;
}

void testCase() {
    string s;
    cin >> s;

    string t = "123456789";

    int sol = 1e9;

    do {
        sol = min(sol, solve(s, t));
    } while (next_permutation(t.begin(), t.end()));

    cout << sol + s.size();
}

signed main() {
    Beevo

    int T = 1;
//    cin >> T;

    while (T--)
        testCase();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 3524kb

input:

6

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Time Limit Exceeded

input:

352836512461179399826927828445163785261417666171453483576899676763764928341261962358737253818463814858565221466575498899898835568743316628247174676952381449147193191788177911797527361649543158616436321694172452689147288835568666918784929695569394655833978219612584637258492511247969998253315177569943...

output:


result: