QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373827#2048. Color the MapKKT89100 ✓29ms3840kbC++173.7kb2024-04-02 07:53:232024-04-02 07:53:25

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 07:53:25]
  • 评测
  • 测评结果:100
  • 用时:29ms
  • 内存:3840kb
  • [2024-04-02 07:53:23]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

struct Point{
    int x,y;
};

int dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}

int cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}

int ccw(Point a,Point b,Point c){
    b={b.x-a.x,b.y-a.y};
    c={c.x-a.x,c.y-a.y};
    if(cross(b,c)>0)return 1; // a,b,c反時計回り
    if(cross(b,c)<0)return -1; // a,b,c時計周り
    if(dot(b,c)<0)return 2; // c,a,b 一直線
    if((b.x*b.x+b.y*b.y)<(c.x*c.x+c.y*c.y))return -2; // a,b,c 一直線
    return 0; // a,c,b 一直線
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        int m=0;
        map<string,int> mp;
        vector<string> s(n);
        vector<vector<pair<int,int>>> v(n); 
        for(int i=0;i<n;i++){
            cin >> s[i];
            if(mp.find(s[i])==mp.end()){
                mp[s[i]]=m; m++;
            }
            int x,y;
            while(cin >> x,x!=-1){
                cin >> y;
                v[i].push_back({x,y});
            }
        }
        auto check=[&](int i,int j)->bool{
            for(int k=0;k<v[i].size();k++){
                Point A={v[i][k].first,v[i][k].second};
                Point B={v[i][(k+1)%v[i].size()].first,v[i][(k+1)%v[i].size()].second};
                for(int kk=0;kk<v[j].size();kk++){
                    Point C={v[j][kk].first,v[j][kk].second};
                    // if(A.x==C.x and A.y==C.y)continue;
                    // if(B.x==C.x and B.y==C.y)continue;
                    if(ccw(A,B,C)==0){
                        if(A.x==C.x and A.y==C.y){
                            Point D={v[j][(kk+1)%v[j].size()].first,v[j][(kk+1)%v[j].size()].second};
                            if(ccw(A,B,D)==0)return true;
                            D={v[j][(kk+v[j].size()-1)%v[j].size()].first,v[j][(kk+v[j].size()-1)%v[j].size()].second};
                            if(ccw(A,B,D)==0)return true;
                        }
                        else if(B.x==C.x and B.y==C.y){
                            Point D={v[j][(kk+1)%v[j].size()].first,v[j][(kk+1)%v[j].size()].second};
                            if(ccw(A,B,D)==0)return true;
                            D={v[j][(kk+v[j].size()-1)%v[j].size()].first,v[j][(kk+v[j].size()-1)%v[j].size()].second};
                            if(ccw(A,B,D)==0)return true;
                        }
                        else return true;
                    }
                }
            }
            return false;
        };
        vector<vector<int>> g(m);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(s[i]==s[j])continue;
                if(check(i,j)){
                    // cout << i << " " << j << endl;
                    g[mp[s[i]]].push_back(mp[s[j]]);
                    g[mp[s[j]]].push_back(mp[s[i]]);
                }
            }
        }
        vector<int> dp(1<<m,1e9);
        dp[0]=0;
        for(int i=1;i<(1<<m);i++){
            for(int j=i;;j=(j-1)&i){
                int k=(j^i);
                bool ok=true;
                for(int u=0;u<m;u++){
                    if((1<<u)&k){
                        for(int t:g[u]){
                            if((1<<t)&k)ok=false;
                        }
                    }
                }
                if(ok){
                    dp[i]=min(dp[i],dp[j]+1);
                }
                if(j==0)break;
            }
        }
        printf("%d\n",dp.back());
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 29ms
memory: 3840kb

input:

6
Blizid
0 0
60 0
60 60
0 60
0 50
50 50
50 10
0 10
-1
Blizid
0 10
10 10
10 50
0 50
-1
Windom
10 10
50 10
40 20
20 20
20 40
10 50
-1
Accent
50 10
50 50
35 50
35 26
-1
Pilot
35 25
35 50
10 50
-1
Blizid
20 20
40 20
20 40
-1
6
Blizid
0 0
60 0
60 60
0 60
0 50
50 50
50 10
0 10
-1
Blizid
0 10
10 10
10 50
0...

output:

3
4
3
2
3
9
10
6
5
6
7
9
1
10
4

result:

ok 15 lines