QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208107 | #1361. Ant Typing | rlong | WA | 28ms | 3864kb | C++14 | 1.2kb | 2023-10-09 05:58:59 | 2023-10-09 05:58:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string str;
map<char, int> mp;
int cnts[12][12];
int cost[12][12];
set<int> s;
int curp[12];
long long best = 99999999999999999LL;
int main() {
cin >> str;
mp['1'] = 1;
mp['2'] = 2;
mp['3'] = 3;
mp['4'] = 4;
mp['5'] = 5;
mp['6'] = 6;
mp['7'] = 7;
mp['8'] = 8;
mp['9'] = 9;
for(int i=0;i<str.length()-1;i++) {
cnts[ mp[str[i]] ][ mp[str[i+1]] ]++;
}
int perm[] = {0,1,2,3,4,5,6,7,8,9};
ll best = 99999999999999999LL;
do {
ll cur = 0;
for(int i=1;i<=9;i++) cost[i][i] = 0;
for(int i=1;i<=8;i++) {
for(int j=i+1;j<=9;j++) {
cost[perm[i]][perm[j]] = cost[perm[j]][perm[i]] = j - i;
}
}
for(int i=1;i<=9;i++) {
for(int j=1;j<=9;j++) {
cur += cnts[perm[i]][perm[j]] * cost[perm[i]][perm[j]];
}
}
cur += cost[1][mp[str[0]]];
best = min(best, cur);
} while(next_permutation(perm+1,perm+1+9));
cout << best + str.length() - 1 << endl;
// 1 3 1 1 3 1 2
}
詳細信息
Test #1:
score: 100
Accepted
time: 24ms
memory: 3660kb
input:
6
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3864kb
input:
352836512461179399826927828445163785261417666171453483576899676763764928341261962358737253818463814858565221466575498899898835568743316628247174676952381449147193191788177911797527361649543158616436321694172452689147288835568666918784929695569394655833978219612584637258492511247969998253315177569943...
output:
392938
result:
wrong answer 1st lines differ - expected: '392933', found: '392938'