QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395826 | #1361. Ant Typing | Omar_Alaa03 | WA | 184ms | 3852kb | C++20 | 1.5kb | 2024-04-21 20:06:25 | 2024-04-21 20:06:26 |
Judging History
answer
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define no "NO"
#define yes "YES"
#define forr(n) for(int i = 0;i < n; i++)
#define d(n) cout<<"value of "<<#n<<" is "<<n<<endl
#define endl '\n'
using namespace std;
const int N = 50 + 5, mode = 1e9 + 7;
void Code() {
string s;
cin >> s;
int grid[10][10] = {};
int n = s.size();
for (int i = 0; i < n - 1; i++) {
grid[s[i] - '0'][s[i + 1] - '0']++;
}
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int mn = 1e9;
do {
int idx;
for (int i = 0; i < 9; i++) {
if (arr[i] == s[0] - '0') {
idx = i;
break;
}
}
int ans = idx;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
int idx1, idx2;
for (int k = 0; k < 9; k++) {
if (arr[k] == i)
idx1 = k;
else if (arr[k] == j)
idx2 = k;
}
int c = abs(idx1 - idx2);
ans += grid[i][j] * c;
}
}
mn = min(ans, mn);
} while (next_permutation(arr, arr + 9));
cout << mn + n << endl;
}
int main() {
fast
int tc = 1;
// cin >> tc;
while (tc--)
Code();
}
詳細信息
Test #1:
score: 100
Accepted
time: 184ms
memory: 3852kb
input:
6
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 183ms
memory: 3792kb
input:
352836512461179399826927828445163785261417666171453483576899676763764928341261962358737253818463814858565221466575498899898835568743316628247174676952381449147193191788177911797527361649543158616436321694172452689147288835568666918784929695569394655833978219612584637258492511247969998253315177569943...
output:
409050
result:
wrong answer 1st lines differ - expected: '392933', found: '409050'