답안 #1119258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119258 2024-11-26T17:43:39 Z modwwe Board Game (JOI24_boardgame) C++17
100 / 100
1743 ms 23212 KB
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int  long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}
void phongbeo();
const int inf = 1e10;
const ll mod2 = 1e9 + 7;
const int  mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0)x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r ;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo();
    // checktime
}
string s;
vector<int> v[50001];
int ans[50001];
int c[50001];
int d[50001];
int cost[50001];
int vis[50001];
int a[50001];
vector<int> cd;
struct cmp
{
    bool operator()(id a,id b)
    {
        return a.a>b.a;
    }
};
void bfs(int c[],bool k)
{
    deque<ib>q;
    for(int i=1; i<=n; i++)
        if(s[i-1]=='1')
        {
            if(k)
            {
                for(auto f:v[i])
                    if(s[f-1]=='1')
                    {
                        q.pb({0,i});
                    }
            }
            else
            {
                q.pb({0,i});
            }
        }
    while(!q.empty())
    {
        ib x=q.front();
        q.pop_front();
        if(vis[x.b]) continue;
        vis[x.b]=1;
        for(auto f:v[x.b])
        {
            c[f]=min(x.a+1,c[f]);
            if(s[f-1]=='1')q.push_front({x.a,f});
            else q.push_back({x.a+1,f});
        }
    }
}
bool cc[50001][301];

namespace k_low
{
priority_queue<id,vector<id>,cmp>p;
void solve()
{
    sort(cd.begin(),cd.end());
    int total=0;
    for(int i=0; i<k; i++)
    {
        p.push({total+s4,s9,i,0});
        cost[i]=i+(k-i-1)*2;
        total+=cd[i];
    }
    while(!p.empty())
    {
        id x=p.top();
        p.pop();
        if(cc[x.b][x.c]) continue;
        cc[x.b][x.c]=1;
        if(x.d)
        {
            ans[x.b]=min(ans[x.b],x.a);
        }
        for(auto f:v[x.b])
            if(s[f-1]=='1')
            {
                if(x.d)
                    ans[f]=min(ans[f],x.a+1);
                p.push({x.a+cost[x.c]+1,f,x.c,1});
            }
            else
            {
                p.push({x.a+1,f,x.c,x.d});
            }
    }
    p.push({0,s9,0,0});
    ans[s9]=0;
    while(!p.empty())
    {
        id x=p.top();
        p.pop();
        if(vis[x.b]) continue;
        vis[x.b]=1;
        for(auto f:v[x.b])
        {
            ans[f]=min(ans[f],x.a+1);
            if(s[f-1]=='0') p.push({x.a+1,f,x.c,x.d});
        }
    }
}
};
namespace k_high
{
int pre[50001];
int cur[50001];
void solve()
{
    for(int i=2; i<=k; i++)
    {
        l=a[i];
        int ci=c[l];
        int di=d[l];
        if(c[l]==0) c[l]+=2;
        if(d[l]==0) d[l]=1;
        c[l]-=2;
        d[l]--;
        if(d[l]+1==inf)
        {
            pre[1]+=c[l];
            cur[1]+=2;
        }
        else
        {
            s3=d[l]-c[l];
            pre[s3]+=d[l];
            pre[s3]-=c[l];
            pre[1]+=c[l];
            cur[s3]++;
            cur[s3]-=2;
            cur[1]+=2;
            pre[s3]-=(s3-1);
        }
        c[l]=ci;
        d[l]=di;

    }
    for(int i=1; i<=n; i++)
        cur[i]+=cur[i-1],
                pre[i]+=pre[i-1]+cur[i];
    deque<ic> q;
    q.push_front({0,s9});
    memset(vis,-1,sizeof vis);
    while(!q.empty())
    {
        ic x=q.front();
        q.pop_front();
        if(vis[x.b]!=-1) continue;
        vis[x.b]=x.a;
        for(auto f:v[x.b])
            if(s[f-1]=='1') q.pb({x.a+1,f});
            else q.push_front({x.a,f});
    }

    q.pb({0,s9,0});
    while(!q.empty())
    {
        ic x=q.front();
        q.pop_front();
        s8=max(s8,x.c);
        if((x.c-vis[x.b])*(k-1)>=n||x.c>n) continue;
        if(cc[x.b][x.c-vis[x.b]]) continue;
        cc[x.b][x.c-vis[x.b]]=1;
        if(s[x.b-1]=='1')s4=1;
        else s4=0;
        ans[x.b]=min(ans[x.b],x.a+pre[x.c-s4]);
        for(auto f:v[x.b])
            if(s[f-1]=='1')q.pb({x.a+1,f,x.c+1});
            else q.pb({x.a+1,f,x.c});
    }
        memset(vis,0,sizeof vis);
}
};
void phongbeo()
{
    cin>>n>>m>>k;
    for(int i=1; i<=m; i++)
        cin>>l>>r,v[l].pb(r),v[r].pb(l);
    cin>>s;
    for(int i=1; i<=n; i++)
        d[i]=inf,c[i]=inf;
    bfs(c,0);
    memset(vis,0,sizeof vis);
    bfs(d,1);
    memset(vis,0,sizeof vis);
    for(int i=1; i<=k; i++)
    {
        cin>>l;
        int ci=c[l];
        int di=d[l];
        if(c[l]==0) c[l]+=2;
        if(d[l]==0) d[l]=1;
        if(i==1)s9=l;
        else c[l]-=2,d[l]--,cd.pb(d[l]-c[l]),s4+=c[l];
        a[i]=l;
        c[l]=ci;
        d[l]=di;
    }
    for(int i=1; i<=n; i++)
        ans[i]=inf;
    if(k<=150)k_low::solve();
    else k_high::solve();
    for(int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}

Compilation message

Main.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:79:9: note: in expansion of macro 'fin'
   79 |         fin(task);
      |         ^~~
Main.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:80:9: note: in expansion of macro 'fou'
   80 |         fou(task);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 24 ms 14052 KB Output is correct
3 Correct 43 ms 22096 KB Output is correct
4 Correct 597 ms 19972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3152 KB Output is correct
2 Correct 37 ms 14412 KB Output is correct
3 Correct 1743 ms 20664 KB Output is correct
4 Correct 59 ms 20552 KB Output is correct
5 Correct 73 ms 22096 KB Output is correct
6 Correct 144 ms 20588 KB Output is correct
7 Correct 162 ms 17316 KB Output is correct
8 Correct 83 ms 19532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3568 KB Output is correct
2 Correct 51 ms 14664 KB Output is correct
3 Correct 623 ms 22360 KB Output is correct
4 Correct 106 ms 21704 KB Output is correct
5 Correct 64 ms 22448 KB Output is correct
6 Correct 92 ms 20468 KB Output is correct
7 Correct 298 ms 20548 KB Output is correct
8 Correct 67 ms 22400 KB Output is correct
9 Correct 25 ms 9012 KB Output is correct
10 Correct 56 ms 12196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2896 KB Output is correct
2 Correct 8 ms 3152 KB Output is correct
3 Correct 5 ms 3204 KB Output is correct
4 Correct 27 ms 3408 KB Output is correct
5 Correct 13 ms 2896 KB Output is correct
6 Correct 6 ms 2640 KB Output is correct
7 Correct 5 ms 2696 KB Output is correct
8 Correct 6 ms 3152 KB Output is correct
9 Correct 7 ms 2896 KB Output is correct
10 Correct 6 ms 2896 KB Output is correct
11 Correct 6 ms 3004 KB Output is correct
12 Correct 5 ms 2948 KB Output is correct
13 Correct 8 ms 3096 KB Output is correct
14 Correct 4 ms 3152 KB Output is correct
15 Correct 25 ms 3156 KB Output is correct
16 Correct 40 ms 3168 KB Output is correct
17 Correct 6 ms 3236 KB Output is correct
18 Correct 4 ms 3052 KB Output is correct
19 Correct 7 ms 2956 KB Output is correct
20 Correct 36 ms 3176 KB Output is correct
21 Correct 5 ms 3152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 20548 KB Output is correct
2 Correct 53 ms 20840 KB Output is correct
3 Correct 64 ms 20460 KB Output is correct
4 Correct 87 ms 20876 KB Output is correct
5 Correct 87 ms 20528 KB Output is correct
6 Correct 58 ms 17408 KB Output is correct
7 Correct 58 ms 11576 KB Output is correct
8 Correct 28 ms 10688 KB Output is correct
9 Correct 33 ms 11080 KB Output is correct
10 Correct 57 ms 17224 KB Output is correct
11 Correct 59 ms 17088 KB Output is correct
12 Correct 73 ms 20276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 20548 KB Output is correct
2 Correct 53 ms 20840 KB Output is correct
3 Correct 64 ms 20460 KB Output is correct
4 Correct 87 ms 20876 KB Output is correct
5 Correct 87 ms 20528 KB Output is correct
6 Correct 58 ms 17408 KB Output is correct
7 Correct 58 ms 11576 KB Output is correct
8 Correct 28 ms 10688 KB Output is correct
9 Correct 33 ms 11080 KB Output is correct
10 Correct 57 ms 17224 KB Output is correct
11 Correct 59 ms 17088 KB Output is correct
12 Correct 73 ms 20276 KB Output is correct
13 Correct 215 ms 20560 KB Output is correct
14 Correct 322 ms 21684 KB Output is correct
15 Correct 1187 ms 22192 KB Output is correct
16 Correct 814 ms 20920 KB Output is correct
17 Correct 800 ms 18760 KB Output is correct
18 Correct 889 ms 19520 KB Output is correct
19 Correct 999 ms 20064 KB Output is correct
20 Correct 736 ms 21024 KB Output is correct
21 Correct 39 ms 11632 KB Output is correct
22 Correct 189 ms 12856 KB Output is correct
23 Correct 378 ms 13024 KB Output is correct
24 Correct 65 ms 18336 KB Output is correct
25 Correct 344 ms 20108 KB Output is correct
26 Correct 682 ms 20104 KB Output is correct
27 Correct 36 ms 13128 KB Output is correct
28 Correct 216 ms 12976 KB Output is correct
29 Correct 459 ms 13132 KB Output is correct
30 Correct 61 ms 20296 KB Output is correct
31 Correct 407 ms 20296 KB Output is correct
32 Correct 896 ms 20512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2896 KB Output is correct
2 Correct 8 ms 3152 KB Output is correct
3 Correct 5 ms 3204 KB Output is correct
4 Correct 27 ms 3408 KB Output is correct
5 Correct 13 ms 2896 KB Output is correct
6 Correct 6 ms 2640 KB Output is correct
7 Correct 5 ms 2696 KB Output is correct
8 Correct 6 ms 3152 KB Output is correct
9 Correct 7 ms 2896 KB Output is correct
10 Correct 6 ms 2896 KB Output is correct
11 Correct 6 ms 3004 KB Output is correct
12 Correct 5 ms 2948 KB Output is correct
13 Correct 8 ms 3096 KB Output is correct
14 Correct 4 ms 3152 KB Output is correct
15 Correct 25 ms 3156 KB Output is correct
16 Correct 40 ms 3168 KB Output is correct
17 Correct 6 ms 3236 KB Output is correct
18 Correct 4 ms 3052 KB Output is correct
19 Correct 7 ms 2956 KB Output is correct
20 Correct 36 ms 3176 KB Output is correct
21 Correct 5 ms 3152 KB Output is correct
22 Correct 104 ms 13404 KB Output is correct
23 Correct 208 ms 14920 KB Output is correct
24 Correct 62 ms 13368 KB Output is correct
25 Correct 199 ms 13652 KB Output is correct
26 Correct 132 ms 13920 KB Output is correct
27 Correct 47 ms 14152 KB Output is correct
28 Correct 86 ms 14056 KB Output is correct
29 Correct 34 ms 14352 KB Output is correct
30 Correct 64 ms 13432 KB Output is correct
31 Correct 35 ms 14276 KB Output is correct
32 Correct 140 ms 10564 KB Output is correct
33 Correct 41 ms 11088 KB Output is correct
34 Correct 568 ms 13064 KB Output is correct
35 Correct 281 ms 14624 KB Output is correct
36 Correct 160 ms 13896 KB Output is correct
37 Correct 108 ms 13652 KB Output is correct
38 Correct 90 ms 13528 KB Output is correct
39 Correct 735 ms 13000 KB Output is correct
40 Correct 164 ms 13772 KB Output is correct
41 Correct 114 ms 13872 KB Output is correct
42 Correct 81 ms 13896 KB Output is correct
43 Correct 57 ms 13768 KB Output is correct
44 Correct 46 ms 13772 KB Output is correct
45 Correct 46 ms 13760 KB Output is correct
46 Correct 45 ms 13904 KB Output is correct
47 Correct 48 ms 13896 KB Output is correct
48 Correct 35 ms 13920 KB Output is correct
49 Correct 30 ms 13904 KB Output is correct
50 Correct 26 ms 13972 KB Output is correct
51 Correct 29 ms 12932 KB Output is correct
52 Correct 40 ms 13128 KB Output is correct
53 Correct 363 ms 13016 KB Output is correct
54 Correct 31 ms 15112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 24 ms 14052 KB Output is correct
3 Correct 43 ms 22096 KB Output is correct
4 Correct 597 ms 19972 KB Output is correct
5 Correct 5 ms 3152 KB Output is correct
6 Correct 37 ms 14412 KB Output is correct
7 Correct 1743 ms 20664 KB Output is correct
8 Correct 59 ms 20552 KB Output is correct
9 Correct 73 ms 22096 KB Output is correct
10 Correct 144 ms 20588 KB Output is correct
11 Correct 162 ms 17316 KB Output is correct
12 Correct 83 ms 19532 KB Output is correct
13 Correct 6 ms 3568 KB Output is correct
14 Correct 51 ms 14664 KB Output is correct
15 Correct 623 ms 22360 KB Output is correct
16 Correct 106 ms 21704 KB Output is correct
17 Correct 64 ms 22448 KB Output is correct
18 Correct 92 ms 20468 KB Output is correct
19 Correct 298 ms 20548 KB Output is correct
20 Correct 67 ms 22400 KB Output is correct
21 Correct 25 ms 9012 KB Output is correct
22 Correct 56 ms 12196 KB Output is correct
23 Correct 7 ms 2896 KB Output is correct
24 Correct 8 ms 3152 KB Output is correct
25 Correct 5 ms 3204 KB Output is correct
26 Correct 27 ms 3408 KB Output is correct
27 Correct 13 ms 2896 KB Output is correct
28 Correct 6 ms 2640 KB Output is correct
29 Correct 5 ms 2696 KB Output is correct
30 Correct 6 ms 3152 KB Output is correct
31 Correct 7 ms 2896 KB Output is correct
32 Correct 6 ms 2896 KB Output is correct
33 Correct 6 ms 3004 KB Output is correct
34 Correct 5 ms 2948 KB Output is correct
35 Correct 8 ms 3096 KB Output is correct
36 Correct 4 ms 3152 KB Output is correct
37 Correct 25 ms 3156 KB Output is correct
38 Correct 40 ms 3168 KB Output is correct
39 Correct 6 ms 3236 KB Output is correct
40 Correct 4 ms 3052 KB Output is correct
41 Correct 7 ms 2956 KB Output is correct
42 Correct 36 ms 3176 KB Output is correct
43 Correct 5 ms 3152 KB Output is correct
44 Correct 64 ms 20548 KB Output is correct
45 Correct 53 ms 20840 KB Output is correct
46 Correct 64 ms 20460 KB Output is correct
47 Correct 87 ms 20876 KB Output is correct
48 Correct 87 ms 20528 KB Output is correct
49 Correct 58 ms 17408 KB Output is correct
50 Correct 58 ms 11576 KB Output is correct
51 Correct 28 ms 10688 KB Output is correct
52 Correct 33 ms 11080 KB Output is correct
53 Correct 57 ms 17224 KB Output is correct
54 Correct 59 ms 17088 KB Output is correct
55 Correct 73 ms 20276 KB Output is correct
56 Correct 215 ms 20560 KB Output is correct
57 Correct 322 ms 21684 KB Output is correct
58 Correct 1187 ms 22192 KB Output is correct
59 Correct 814 ms 20920 KB Output is correct
60 Correct 800 ms 18760 KB Output is correct
61 Correct 889 ms 19520 KB Output is correct
62 Correct 999 ms 20064 KB Output is correct
63 Correct 736 ms 21024 KB Output is correct
64 Correct 39 ms 11632 KB Output is correct
65 Correct 189 ms 12856 KB Output is correct
66 Correct 378 ms 13024 KB Output is correct
67 Correct 65 ms 18336 KB Output is correct
68 Correct 344 ms 20108 KB Output is correct
69 Correct 682 ms 20104 KB Output is correct
70 Correct 36 ms 13128 KB Output is correct
71 Correct 216 ms 12976 KB Output is correct
72 Correct 459 ms 13132 KB Output is correct
73 Correct 61 ms 20296 KB Output is correct
74 Correct 407 ms 20296 KB Output is correct
75 Correct 896 ms 20512 KB Output is correct
76 Correct 104 ms 13404 KB Output is correct
77 Correct 208 ms 14920 KB Output is correct
78 Correct 62 ms 13368 KB Output is correct
79 Correct 199 ms 13652 KB Output is correct
80 Correct 132 ms 13920 KB Output is correct
81 Correct 47 ms 14152 KB Output is correct
82 Correct 86 ms 14056 KB Output is correct
83 Correct 34 ms 14352 KB Output is correct
84 Correct 64 ms 13432 KB Output is correct
85 Correct 35 ms 14276 KB Output is correct
86 Correct 140 ms 10564 KB Output is correct
87 Correct 41 ms 11088 KB Output is correct
88 Correct 568 ms 13064 KB Output is correct
89 Correct 281 ms 14624 KB Output is correct
90 Correct 160 ms 13896 KB Output is correct
91 Correct 108 ms 13652 KB Output is correct
92 Correct 90 ms 13528 KB Output is correct
93 Correct 735 ms 13000 KB Output is correct
94 Correct 164 ms 13772 KB Output is correct
95 Correct 114 ms 13872 KB Output is correct
96 Correct 81 ms 13896 KB Output is correct
97 Correct 57 ms 13768 KB Output is correct
98 Correct 46 ms 13772 KB Output is correct
99 Correct 46 ms 13760 KB Output is correct
100 Correct 45 ms 13904 KB Output is correct
101 Correct 48 ms 13896 KB Output is correct
102 Correct 35 ms 13920 KB Output is correct
103 Correct 30 ms 13904 KB Output is correct
104 Correct 26 ms 13972 KB Output is correct
105 Correct 29 ms 12932 KB Output is correct
106 Correct 40 ms 13128 KB Output is correct
107 Correct 363 ms 13016 KB Output is correct
108 Correct 31 ms 15112 KB Output is correct
109 Correct 181 ms 22192 KB Output is correct
110 Correct 633 ms 23212 KB Output is correct
111 Correct 1204 ms 22360 KB Output is correct
112 Correct 1518 ms 20772 KB Output is correct
113 Correct 470 ms 21368 KB Output is correct
114 Correct 1095 ms 23080 KB Output is correct
115 Correct 1666 ms 21840 KB Output is correct
116 Correct 714 ms 21260 KB Output is correct
117 Correct 764 ms 21364 KB Output is correct
118 Correct 64 ms 10236 KB Output is correct
119 Correct 81 ms 10844 KB Output is correct
120 Correct 150 ms 19784 KB Output is correct
121 Correct 64 ms 23156 KB Output is correct
122 Correct 623 ms 22580 KB Output is correct
123 Correct 360 ms 21916 KB Output is correct
124 Correct 246 ms 21228 KB Output is correct
125 Correct 186 ms 21092 KB Output is correct
126 Correct 1319 ms 20340 KB Output is correct
127 Correct 386 ms 21064 KB Output is correct
128 Correct 270 ms 21204 KB Output is correct
129 Correct 183 ms 21064 KB Output is correct
130 Correct 152 ms 21188 KB Output is correct
131 Correct 133 ms 21224 KB Output is correct
132 Correct 113 ms 21188 KB Output is correct
133 Correct 123 ms 21692 KB Output is correct
134 Correct 104 ms 21692 KB Output is correct
135 Correct 92 ms 21176 KB Output is correct
136 Correct 79 ms 21204 KB Output is correct
137 Correct 78 ms 20960 KB Output is correct
138 Correct 81 ms 20928 KB Output is correct
139 Correct 70 ms 21208 KB Output is correct
140 Correct 66 ms 19784 KB Output is correct
141 Correct 110 ms 19872 KB Output is correct
142 Correct 151 ms 20916 KB Output is correct
143 Correct 87 ms 22992 KB Output is correct