답안 #1119051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119051 2024-11-26T14:17:31 Z modwwe Board Game (JOI24_boardgame) C++17
35 / 100
2119 ms 21584 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 = 1e18;
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];
bool cc[50001][101][2];
bool vis[50001];
vector<int> cd;
struct cmp
{
    bool operator()(id a,id b)
    {
        return a.a>b.a;
    }
};
priority_queue<id,vector<id>,cmp>p;
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});
        }
    }
}
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];
        c[l]=ci;
        d[l]=di;
    }
    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];
    }
    for(int i=1; i<=n; i++)
        ans[i]=inf;
    while(!p.empty())
    {
        id x=p.top();
        p.pop();
        if(cc[x.b][x.c][x.d]) continue;
        cc[x.b][x.c][x.d]=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});
        }
    }
    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 53 ms 3180 KB Output is correct
2 Correct 154 ms 10360 KB Output is correct
3 Correct 200 ms 14968 KB Output is correct
4 Correct 626 ms 15404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 2748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2524 KB Output is correct
2 Correct 6 ms 2388 KB Output is correct
3 Incorrect 61 ms 2548 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 15560 KB Output is correct
2 Correct 43 ms 15868 KB Output is correct
3 Correct 40 ms 15436 KB Output is correct
4 Correct 90 ms 15732 KB Output is correct
5 Correct 99 ms 15604 KB Output is correct
6 Correct 59 ms 13056 KB Output is correct
7 Correct 83 ms 14832 KB Output is correct
8 Correct 35 ms 8648 KB Output is correct
9 Correct 26 ms 8532 KB Output is correct
10 Correct 55 ms 13392 KB Output is correct
11 Correct 59 ms 13364 KB Output is correct
12 Correct 68 ms 15180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 15560 KB Output is correct
2 Correct 43 ms 15868 KB Output is correct
3 Correct 40 ms 15436 KB Output is correct
4 Correct 90 ms 15732 KB Output is correct
5 Correct 99 ms 15604 KB Output is correct
6 Correct 59 ms 13056 KB Output is correct
7 Correct 83 ms 14832 KB Output is correct
8 Correct 35 ms 8648 KB Output is correct
9 Correct 26 ms 8532 KB Output is correct
10 Correct 55 ms 13392 KB Output is correct
11 Correct 59 ms 13364 KB Output is correct
12 Correct 68 ms 15180 KB Output is correct
13 Correct 298 ms 15628 KB Output is correct
14 Correct 276 ms 16700 KB Output is correct
15 Correct 1067 ms 17248 KB Output is correct
16 Correct 844 ms 15840 KB Output is correct
17 Correct 805 ms 14684 KB Output is correct
18 Correct 1695 ms 21584 KB Output is correct
19 Correct 2119 ms 20564 KB Output is correct
20 Correct 740 ms 15872 KB Output is correct
21 Correct 36 ms 8940 KB Output is correct
22 Correct 369 ms 9616 KB Output is correct
23 Correct 785 ms 9860 KB Output is correct
24 Correct 80 ms 14120 KB Output is correct
25 Correct 605 ms 15216 KB Output is correct
26 Correct 1297 ms 15200 KB Output is correct
27 Correct 37 ms 9804 KB Output is correct
28 Correct 353 ms 9804 KB Output is correct
29 Correct 869 ms 9744 KB Output is correct
30 Correct 71 ms 15192 KB Output is correct
31 Correct 742 ms 15316 KB Output is correct
32 Correct 1564 ms 15232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2524 KB Output is correct
2 Correct 6 ms 2388 KB Output is correct
3 Incorrect 61 ms 2548 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 3180 KB Output is correct
2 Correct 154 ms 10360 KB Output is correct
3 Correct 200 ms 14968 KB Output is correct
4 Correct 626 ms 15404 KB Output is correct
5 Incorrect 88 ms 2884 KB Output isn't correct
6 Halted 0 ms 0 KB -