QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#59669 | #1361. Ant Typing | Sa3tElSefr# | WA | 21ms | 3496kb | C++20 | 999b | 2022-10-31 18:41:06 | 2022-10-31 18:41:06 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ld double
using namespace std;
const int N = 2e5 + 5, lg = 19, mod = 1e9 + 7;
ll f[15][15];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
s = "9" + s;
for(int i = 0; i + 1 < (int) s.size(); i++) {
f[s[i] - '0'][s[i + 1] - '0']++;
}
vector<int> p(9);
iota(p.begin(), p.end(), 1);
const ll inf = 1e18;
ll ans = inf;
vector<int> pos(10);
do{
ll t = 0;
for(int i = 0; i < 9; i++) pos[p[i]] = i;
for(int i = 1; i <= 9; i++) {
for(int j = 1; j <= 9; j++) {
t += f[i][j] * abs(pos[i] - pos[j]);
}
}
ans = min(ans, t + (int) s.size() - 1);
}while(next_permutation(p.begin(), p.end()));
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 21ms
memory: 3496kb
input:
6
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'