QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59717 | #1361. Ant Typing | Beevo# | TL | 5ms | 3524kb | C++23 | 810b | 2022-10-31 21:57:41 | 2022-10-31 21:57:43 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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...