QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208067 | #1361. Ant Typing | rlong | TL | 0ms | 0kb | C++14 | 1.2kb | 2023-10-09 05:06:11 | 2023-10-09 05:06:11 |
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;
void perm() {
if(s.size() == 0) {
// compute costs
ll cur = 0;
for(int i=1;i<=9;i++) cost[i][i] = 0;
for(int i=1;i<=9;i++) {
for(int j=1;j<=9;j++) {
cur += cnts[curp[i]][curp[j]] += max(j-i,i-j) * cost[curp[i]][curp[j]];
}
}
best = min(best, cur);
return;
}
int k = s.size();
for(auto it = s.begin(); it != s.end(); it++) {
int val = *it;
curp[k] = val;
s.erase(val);
perm();
s.insert(val);
}
}
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]] ]++;
}
for(int i=1;i<=9;i++) s.insert(i);
perm();
cout << best << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
6