Submission #1119266

# Submission time Handle Problem Language Result Execution time Memory
1119266 2024-11-26T17:50:26 Z modwwe Board Game (JOI24_boardgame) C++17
100 / 100
2212 ms 57388 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][1001];

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});
            }
    }
    deque<ib> q;
    q.pb({0,s9});
    ans[s9]=0;
    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])
        {
            ans[f]=min(ans[f],x.a+1);
            if(s[f-1]=='0') q.pb({x.a+1,f});
        }
    }
}
};
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<=90)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);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5200 KB Output is correct
2 Correct 45 ms 34448 KB Output is correct
3 Correct 87 ms 57024 KB Output is correct
4 Correct 66 ms 55152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5360 KB Output is correct
2 Correct 48 ms 34736 KB Output is correct
3 Correct 1308 ms 55156 KB Output is correct
4 Correct 87 ms 54344 KB Output is correct
5 Correct 80 ms 55652 KB Output is correct
6 Correct 116 ms 54340 KB Output is correct
7 Correct 155 ms 44140 KB Output is correct
8 Correct 89 ms 50952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5200 KB Output is correct
2 Correct 59 ms 34244 KB Output is correct
3 Correct 652 ms 56088 KB Output is correct
4 Correct 138 ms 55700 KB Output is correct
5 Correct 85 ms 56056 KB Output is correct
6 Correct 127 ms 54840 KB Output is correct
7 Correct 336 ms 54224 KB Output is correct
8 Correct 84 ms 56000 KB Output is correct
9 Correct 40 ms 15440 KB Output is correct
10 Correct 46 ms 18728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3920 KB Output is correct
2 Correct 11 ms 6736 KB Output is correct
3 Correct 8 ms 5200 KB Output is correct
4 Correct 28 ms 5484 KB Output is correct
5 Correct 11 ms 4352 KB Output is correct
6 Correct 9 ms 4176 KB Output is correct
7 Correct 7 ms 3664 KB Output is correct
8 Correct 6 ms 5200 KB Output is correct
9 Correct 7 ms 4432 KB Output is correct
10 Correct 6 ms 4432 KB Output is correct
11 Correct 6 ms 6784 KB Output is correct
12 Correct 7 ms 6736 KB Output is correct
13 Correct 11 ms 6480 KB Output is correct
14 Correct 9 ms 5456 KB Output is correct
15 Correct 29 ms 5200 KB Output is correct
16 Correct 9 ms 5200 KB Output is correct
17 Correct 9 ms 6748 KB Output is correct
18 Correct 7 ms 4944 KB Output is correct
19 Correct 13 ms 4944 KB Output is correct
20 Correct 8 ms 5284 KB Output is correct
21 Correct 10 ms 5260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 54476 KB Output is correct
2 Correct 80 ms 54584 KB Output is correct
3 Correct 77 ms 54244 KB Output is correct
4 Correct 105 ms 54480 KB Output is correct
5 Correct 108 ms 54124 KB Output is correct
6 Correct 108 ms 44616 KB Output is correct
7 Correct 46 ms 18416 KB Output is correct
8 Correct 39 ms 26192 KB Output is correct
9 Correct 41 ms 26184 KB Output is correct
10 Correct 67 ms 42312 KB Output is correct
11 Correct 74 ms 42312 KB Output is correct
12 Correct 87 ms 54012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 54476 KB Output is correct
2 Correct 80 ms 54584 KB Output is correct
3 Correct 77 ms 54244 KB Output is correct
4 Correct 105 ms 54480 KB Output is correct
5 Correct 108 ms 54124 KB Output is correct
6 Correct 108 ms 44616 KB Output is correct
7 Correct 46 ms 18416 KB Output is correct
8 Correct 39 ms 26192 KB Output is correct
9 Correct 41 ms 26184 KB Output is correct
10 Correct 67 ms 42312 KB Output is correct
11 Correct 74 ms 42312 KB Output is correct
12 Correct 87 ms 54012 KB Output is correct
13 Correct 207 ms 54224 KB Output is correct
14 Correct 327 ms 55084 KB Output is correct
15 Correct 1039 ms 55944 KB Output is correct
16 Correct 945 ms 54576 KB Output is correct
17 Correct 923 ms 45540 KB Output is correct
18 Correct 1129 ms 46300 KB Output is correct
19 Correct 1245 ms 43208 KB Output is correct
20 Correct 869 ms 54408 KB Output is correct
21 Correct 60 ms 27736 KB Output is correct
22 Correct 235 ms 32580 KB Output is correct
23 Correct 544 ms 34700 KB Output is correct
24 Correct 95 ms 46408 KB Output is correct
25 Correct 367 ms 53244 KB Output is correct
26 Correct 2082 ms 56504 KB Output is correct
27 Correct 62 ms 33220 KB Output is correct
28 Correct 258 ms 33264 KB Output is correct
29 Correct 424 ms 34008 KB Output is correct
30 Correct 110 ms 54088 KB Output is correct
31 Correct 458 ms 54060 KB Output is correct
32 Correct 1233 ms 56040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3920 KB Output is correct
2 Correct 11 ms 6736 KB Output is correct
3 Correct 8 ms 5200 KB Output is correct
4 Correct 28 ms 5484 KB Output is correct
5 Correct 11 ms 4352 KB Output is correct
6 Correct 9 ms 4176 KB Output is correct
7 Correct 7 ms 3664 KB Output is correct
8 Correct 6 ms 5200 KB Output is correct
9 Correct 7 ms 4432 KB Output is correct
10 Correct 6 ms 4432 KB Output is correct
11 Correct 6 ms 6784 KB Output is correct
12 Correct 7 ms 6736 KB Output is correct
13 Correct 11 ms 6480 KB Output is correct
14 Correct 9 ms 5456 KB Output is correct
15 Correct 29 ms 5200 KB Output is correct
16 Correct 9 ms 5200 KB Output is correct
17 Correct 9 ms 6748 KB Output is correct
18 Correct 7 ms 4944 KB Output is correct
19 Correct 13 ms 4944 KB Output is correct
20 Correct 8 ms 5284 KB Output is correct
21 Correct 10 ms 5260 KB Output is correct
22 Correct 100 ms 33428 KB Output is correct
23 Correct 195 ms 35208 KB Output is correct
24 Correct 69 ms 33552 KB Output is correct
25 Correct 193 ms 33888 KB Output is correct
26 Correct 129 ms 34120 KB Output is correct
27 Correct 52 ms 34128 KB Output is correct
28 Correct 110 ms 34532 KB Output is correct
29 Correct 49 ms 34244 KB Output is correct
30 Correct 72 ms 33580 KB Output is correct
31 Correct 48 ms 34244 KB Output is correct
32 Correct 154 ms 23828 KB Output is correct
33 Correct 42 ms 24288 KB Output is correct
34 Correct 334 ms 34572 KB Output is correct
35 Correct 321 ms 34632 KB Output is correct
36 Correct 195 ms 33976 KB Output is correct
37 Correct 161 ms 33748 KB Output is correct
38 Correct 100 ms 33316 KB Output is correct
39 Correct 222 ms 34176 KB Output is correct
40 Correct 181 ms 34044 KB Output is correct
41 Correct 145 ms 33948 KB Output is correct
42 Correct 106 ms 34032 KB Output is correct
43 Correct 86 ms 34052 KB Output is correct
44 Correct 79 ms 34104 KB Output is correct
45 Correct 85 ms 34068 KB Output is correct
46 Correct 76 ms 34020 KB Output is correct
47 Correct 81 ms 34100 KB Output is correct
48 Correct 71 ms 34084 KB Output is correct
49 Correct 70 ms 34460 KB Output is correct
50 Correct 64 ms 34052 KB Output is correct
51 Correct 58 ms 33096 KB Output is correct
52 Correct 75 ms 33504 KB Output is correct
53 Correct 428 ms 33988 KB Output is correct
54 Correct 54 ms 35144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5200 KB Output is correct
2 Correct 45 ms 34448 KB Output is correct
3 Correct 87 ms 57024 KB Output is correct
4 Correct 66 ms 55152 KB Output is correct
5 Correct 7 ms 5360 KB Output is correct
6 Correct 48 ms 34736 KB Output is correct
7 Correct 1308 ms 55156 KB Output is correct
8 Correct 87 ms 54344 KB Output is correct
9 Correct 80 ms 55652 KB Output is correct
10 Correct 116 ms 54340 KB Output is correct
11 Correct 155 ms 44140 KB Output is correct
12 Correct 89 ms 50952 KB Output is correct
13 Correct 8 ms 5200 KB Output is correct
14 Correct 59 ms 34244 KB Output is correct
15 Correct 652 ms 56088 KB Output is correct
16 Correct 138 ms 55700 KB Output is correct
17 Correct 85 ms 56056 KB Output is correct
18 Correct 127 ms 54840 KB Output is correct
19 Correct 336 ms 54224 KB Output is correct
20 Correct 84 ms 56000 KB Output is correct
21 Correct 40 ms 15440 KB Output is correct
22 Correct 46 ms 18728 KB Output is correct
23 Correct 6 ms 3920 KB Output is correct
24 Correct 11 ms 6736 KB Output is correct
25 Correct 8 ms 5200 KB Output is correct
26 Correct 28 ms 5484 KB Output is correct
27 Correct 11 ms 4352 KB Output is correct
28 Correct 9 ms 4176 KB Output is correct
29 Correct 7 ms 3664 KB Output is correct
30 Correct 6 ms 5200 KB Output is correct
31 Correct 7 ms 4432 KB Output is correct
32 Correct 6 ms 4432 KB Output is correct
33 Correct 6 ms 6784 KB Output is correct
34 Correct 7 ms 6736 KB Output is correct
35 Correct 11 ms 6480 KB Output is correct
36 Correct 9 ms 5456 KB Output is correct
37 Correct 29 ms 5200 KB Output is correct
38 Correct 9 ms 5200 KB Output is correct
39 Correct 9 ms 6748 KB Output is correct
40 Correct 7 ms 4944 KB Output is correct
41 Correct 13 ms 4944 KB Output is correct
42 Correct 8 ms 5284 KB Output is correct
43 Correct 10 ms 5260 KB Output is correct
44 Correct 107 ms 54476 KB Output is correct
45 Correct 80 ms 54584 KB Output is correct
46 Correct 77 ms 54244 KB Output is correct
47 Correct 105 ms 54480 KB Output is correct
48 Correct 108 ms 54124 KB Output is correct
49 Correct 108 ms 44616 KB Output is correct
50 Correct 46 ms 18416 KB Output is correct
51 Correct 39 ms 26192 KB Output is correct
52 Correct 41 ms 26184 KB Output is correct
53 Correct 67 ms 42312 KB Output is correct
54 Correct 74 ms 42312 KB Output is correct
55 Correct 87 ms 54012 KB Output is correct
56 Correct 207 ms 54224 KB Output is correct
57 Correct 327 ms 55084 KB Output is correct
58 Correct 1039 ms 55944 KB Output is correct
59 Correct 945 ms 54576 KB Output is correct
60 Correct 923 ms 45540 KB Output is correct
61 Correct 1129 ms 46300 KB Output is correct
62 Correct 1245 ms 43208 KB Output is correct
63 Correct 869 ms 54408 KB Output is correct
64 Correct 60 ms 27736 KB Output is correct
65 Correct 235 ms 32580 KB Output is correct
66 Correct 544 ms 34700 KB Output is correct
67 Correct 95 ms 46408 KB Output is correct
68 Correct 367 ms 53244 KB Output is correct
69 Correct 2082 ms 56504 KB Output is correct
70 Correct 62 ms 33220 KB Output is correct
71 Correct 258 ms 33264 KB Output is correct
72 Correct 424 ms 34008 KB Output is correct
73 Correct 110 ms 54088 KB Output is correct
74 Correct 458 ms 54060 KB Output is correct
75 Correct 1233 ms 56040 KB Output is correct
76 Correct 100 ms 33428 KB Output is correct
77 Correct 195 ms 35208 KB Output is correct
78 Correct 69 ms 33552 KB Output is correct
79 Correct 193 ms 33888 KB Output is correct
80 Correct 129 ms 34120 KB Output is correct
81 Correct 52 ms 34128 KB Output is correct
82 Correct 110 ms 34532 KB Output is correct
83 Correct 49 ms 34244 KB Output is correct
84 Correct 72 ms 33580 KB Output is correct
85 Correct 48 ms 34244 KB Output is correct
86 Correct 154 ms 23828 KB Output is correct
87 Correct 42 ms 24288 KB Output is correct
88 Correct 334 ms 34572 KB Output is correct
89 Correct 321 ms 34632 KB Output is correct
90 Correct 195 ms 33976 KB Output is correct
91 Correct 161 ms 33748 KB Output is correct
92 Correct 100 ms 33316 KB Output is correct
93 Correct 222 ms 34176 KB Output is correct
94 Correct 181 ms 34044 KB Output is correct
95 Correct 145 ms 33948 KB Output is correct
96 Correct 106 ms 34032 KB Output is correct
97 Correct 86 ms 34052 KB Output is correct
98 Correct 79 ms 34104 KB Output is correct
99 Correct 85 ms 34068 KB Output is correct
100 Correct 76 ms 34020 KB Output is correct
101 Correct 81 ms 34100 KB Output is correct
102 Correct 71 ms 34084 KB Output is correct
103 Correct 70 ms 34460 KB Output is correct
104 Correct 64 ms 34052 KB Output is correct
105 Correct 58 ms 33096 KB Output is correct
106 Correct 75 ms 33504 KB Output is correct
107 Correct 428 ms 33988 KB Output is correct
108 Correct 54 ms 35144 KB Output is correct
109 Correct 225 ms 55744 KB Output is correct
110 Correct 969 ms 56904 KB Output is correct
111 Correct 2212 ms 56152 KB Output is correct
112 Correct 905 ms 55728 KB Output is correct
113 Correct 486 ms 55136 KB Output is correct
114 Correct 1124 ms 57256 KB Output is correct
115 Correct 1489 ms 56136 KB Output is correct
116 Correct 679 ms 55368 KB Output is correct
117 Correct 593 ms 48200 KB Output is correct
118 Correct 68 ms 17044 KB Output is correct
119 Correct 106 ms 17536 KB Output is correct
120 Correct 174 ms 45024 KB Output is correct
121 Correct 84 ms 57388 KB Output is correct
122 Correct 677 ms 56724 KB Output is correct
123 Correct 428 ms 55556 KB Output is correct
124 Correct 294 ms 55112 KB Output is correct
125 Correct 240 ms 55124 KB Output is correct
126 Correct 654 ms 55760 KB Output is correct
127 Correct 443 ms 55960 KB Output is correct
128 Correct 322 ms 55360 KB Output is correct
129 Correct 221 ms 55408 KB Output is correct
130 Correct 199 ms 55368 KB Output is correct
131 Correct 181 ms 55368 KB Output is correct
132 Correct 143 ms 55332 KB Output is correct
133 Correct 130 ms 55368 KB Output is correct
134 Correct 100 ms 55428 KB Output is correct
135 Correct 99 ms 55268 KB Output is correct
136 Correct 98 ms 55368 KB Output is correct
137 Correct 96 ms 55268 KB Output is correct
138 Correct 88 ms 55308 KB Output is correct
139 Correct 84 ms 55408 KB Output is correct
140 Correct 69 ms 54184 KB Output is correct
141 Correct 135 ms 53976 KB Output is correct
142 Correct 146 ms 55352 KB Output is correct
143 Correct 92 ms 57328 KB Output is correct