QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208094 | #1361. Ant Typing | rlong | WA | 24ms | 3588kb | C++14 | 1.2kb | 2023-10-09 05:43:52 | 2023-10-09 05:43:52 |
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] = 1;
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]];
}
}
best = min(best, cur);
} while(next_permutation(perm+1,perm+1+9));
cout << best+1+str.length() << endl;
// 1 3 1 1 3 1 2
}
详细
Test #1:
score: 0
Wrong Answer
time: 24ms
memory: 3588kb
input:
6
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'