답안 #433836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433836 2021-06-20T11:15:50 Z AmineTrabelsi Love Polygon (BOI18_polygon) C++14
0 / 100
2000 ms 9084 KB
#include "bits/stdc++.h"
using namespace std;
// Hi 

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    vector<int> go(n);
    map<string,int> mp;
    int nxt = 0;
    for(int i=0;i<n;i++){
        string s,t;
        cin>>s>>t;
        int first = 0,second = 0;
        if(mp.find(s) != mp.end()){
            first = mp[s];
        }else{
            first = nxt;
            mp[s] = nxt++;
        }
        if(mp.find(t) != mp.end()){
            second = mp[t];
        }else{
            second = nxt;
            mp[t] = nxt++;
        }
        go[first] = second;
    }
    vector<int> perm;
    for(int i=0;i<n;i++){
        perm.push_back(i);
    }
    int ans = 1000000009;
    do{
        bool can = 1;
        for(int i=0;i<n;i++){
            if(perm[i] == i || perm[perm[i]] != i){
                can = 0;
                break;
            }
        }
        if(can){
            int cnt = 0;
            for(int i=0;i<n;i++){
                //cout <<perm[i]<<" ";
                cnt += (perm[i] != go[i]);
            }
            //cout<<'\n';
            ans = min(ans,cnt);
        }
    }while(next_permutation(perm.begin(),perm.end()));
    cout << (ans == 1000000009 ? -1 : ans) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2057 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 2081 ms 9068 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 9084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2057 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -