QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395826#1361. Ant TypingOmar_Alaa03WA 184ms3852kbC++201.5kb2024-04-21 20:06:252024-04-21 20:06:26

Judging History

This is the latest submission verdict.

  • [2024-04-21 20:06:26]
  • Judged
  • Verdict: WA
  • Time: 184ms
  • Memory: 3852kb
  • [2024-04-21 20:06:25]
  • Submitted

answer

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define  ld long double
#define no "NO"
#define yes "YES"
#define forr(n) for(int i = 0;i < n; i++)
#define d(n) cout<<"value of "<<#n<<" is "<<n<<endl
#define endl '\n'
using namespace std;
const int N = 50 + 5, mode = 1e9 + 7;

void Code() {
    string s;
    cin >> s;
    int grid[10][10] = {};
    int n = s.size();
    for (int i = 0; i < n - 1; i++) {
        grid[s[i] - '0'][s[i + 1] - '0']++;
    }


    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int mn = 1e9;
    do {
        int idx;
        for (int i = 0; i < 9; i++) {
            if (arr[i] == s[0] - '0') {
                idx = i;
                break;
            }
        }
        int ans = idx;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                int idx1, idx2;
                for (int k = 0; k < 9; k++) {
                    if (arr[k] == i)
                        idx1 = k;
                    else if (arr[k] == j)
                        idx2 = k;
                }
                int c = abs(idx1 - idx2);
                ans += grid[i][j] * c;
            }
        }
        mn = min(ans, mn);
    } while (next_permutation(arr, arr + 9));

    cout << mn + n << endl;

}


int main() {
    fast
    int tc = 1;
//    cin >> tc;

    while (tc--)
        Code();
}

详细

Test #1:

score: 100
Accepted
time: 184ms
memory: 3852kb

input:

6

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Wrong Answer
time: 183ms
memory: 3792kb

input:

352836512461179399826927828445163785261417666171453483576899676763764928341261962358737253818463814858565221466575498899898835568743316628247174676952381449147193191788177911797527361649543158616436321694172452689147288835568666918784929695569394655833978219612584637258492511247969998253315177569943...

output:

409050

result:

wrong answer 1st lines differ - expected: '392933', found: '409050'