Submission

Status:

PPPPPPPxPxPPPPPPPxPP

Subtask/Task Score:

85/100

Score: 85

User: Peam

Problemset: สุ่มสลับ

Language: cpp

Time: 0.010 second

Submitted On: 2025-10-20 19:47:46

#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

void R4U4RT4T(){
    string s;
    cin >> s;

    //R4U4RT4T
    //R U RT T

}

void circle(){
    int t, h, k;
    cin >> t;
    if(t > 0){
        h = t / 10;
        k = t % 10;
    }
    else if(t < 0){
        h = t / 10;
        k = t % 10 * -1;
    }
    else{
        return;
    }

    // cout << h << ' ' << k << endl;

    int r;
    cin >> r;

    vector<pair<int, int>> cordyes;
    vector<pair<int, int>> cordno;
    vector<pair<int, int>> cord(3);
    bool ans[3];
    for(int i = 0; i < 3; i++){

            int t;
            cin >> t;

            int x, y;
            if(t > 0){
                x = t / 10;
                y = t % 10;
            }
            else{
                x = t / 10;
                y = t % 10 * -1;
            }

            //apply formula
            if( ((x - h) * (x - h)) + ((y - k) * (y - k)) <= r * r){
                ans[i] = true;
                cord[i].first = x;
                cord[i].second = y;
            }
            else{
                ans[i] = false;
                cord[i].first = x;
                cord[i].second = y;
            }

    }

    //cord in -> print YES: cord1 cord2
    //cord not in -> print NO: cord1 cord2
    //cord in only -> print YES: cord1 cord2 ... (don't print NO: ...)
    //

    //cord yes
    int y = 0;
    for(int i = 0; i < 3; i++){
        if(ans[i]){
            if(y == 0){
                cout << "YES: ";
                y = 1;
            }
            cout << cord[i].first << cord[i].second << " ";
        }
    }

    if(y == 1){
        cout << endl;
    }

    //cord no
    int n = 0;
    for(int i = 0; i < 3; i++){
        if(!ans[i]){
            if(n == 0){
                cout << "NO: ";
                n = 1;
            }
            cout << cord[i].first << cord[i].second << " ";
        }
    }

    // (h, k) = (2, 1)
    // cord
    // (2, 3) (2, 4) (1, 2)

}

double distance(double x1, double y1, double x2, double y2){
    double dis = sqrt( ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)) );
    return dis;
}

void permutation(string s, int l, int r, vector<string> &v){
    for(int i = l; i < r; i++){
        swap(s[i], s[l]);
        permutation(s, l + 1, r, v);
        swap(s[i], s[l]);
    }

    if(l == r){
        v.push_back(s);
        return;
    }

}


int main(){
    int n;
    cin >> n;

    string s;
    cin >> s;
    string search(s);

    vector<string> v1;
    permutation(s, 0, s.size(), v1);

    //sort
    sort(v1.begin(), v1.end());

    // for(string i : v1){
    //     cout << i << " ";
    // }

    // cout << endl;

    auto it = find(v1.begin(), v1.end(), search);
    if(it != v1.end()){
        cout << distance(v1.begin(), it) + 1;
    }
    else{
        return 0;
    }


    // vector<string>::iterator it = find(v1.begin(), v1.end(), search);

    // if(it != v1.end()){
    //     cout << "Found at: " << distance(v1.begin(), it) << endl;
    // }
    // else{
    //     cout << "Not found\n";
    // }



    return 0;
}