QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59669#1361. Ant TypingSa3tElSefr#WA 21ms3496kbC++20999b2022-10-31 18:41:062022-10-31 18:41:06

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-31 18:41:06]
  • Judged
  • Verdict: WA
  • Time: 21ms
  • Memory: 3496kb
  • [2022-10-31 18:41:06]
  • Submitted

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'