답안 #697181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697181 2023-02-08T17:35:13 Z bin9638 Raspad (COI17_raspad) C++17
61 / 100
6000 ms 43468 KB
#include<bits/stdc++.h>

using namespace std;
#define N  100010
#define ll long long
#define ii pair<int,int>
#define fs first
#define sc second
#define pb push_back
#define iii pair<int,ii>
#define int ll

#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")

int f[N],a[N][55],n,m;

struct haha
{
    int val=0,sum=0,sl=0,cnt[52]={},id[52]={},ktr[52]={};

    int get(int mod)
    {
        int res=0;
        for(int i=1;i<=m;i++)
            res=(res+f[i]%mod*id[i])%mod;
        return res;
    }

    void DFS(int u,int dem,int h)
    {
        ktr[u]=dem;
        if(ktr[u-1]==0&&a[h][u-1]==1)
            DFS(u-1,dem,h);
        if(ktr[u+1]==0&&a[h][u+1]==1)
            DFS(u+1,dem,h);
        for(int i=1;i<=m;i++)
            if(ktr[i]==0&&id[i]==id[u])
                DFS(i,dem,h);
    }

    void build(int h)
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=m;i++)
            if(id[i]!=0)
                cnt[id[i]]=1;
        int dem=m+1;
        for(int i=1;i<=m;i++)
            if(a[h][i]==0)
                id[i]=0;
                else{
                    if(id[i]==0)
                        id[i]=++dem;
                }
        for(int i=1;i<=m;i++)
            if(id[i]!=0&&id[i]<=m)
                cnt[id[i]]=0;
        for(int i=1;i<=m;i++)
            if(cnt[i]>0)
                sum+=sl;
        dem=0;
        memset(ktr,0,sizeof(ktr));
        for(int i=1;i<=m;i++)
            if(ktr[i]==0&&id[i]!=0)
            {
                dem++;
                DFS(i,dem,h);
            }
        for(int i=1;i<=m;i++)
            id[i]=ktr[i];
        val=get(1e9+8277);
    }

    int solve()
    {
        memset(cnt,0,sizeof(cnt));
         for(int i=1;i<=m;i++)
            if(id[i]!=0)
                cnt[id[i]]=1;
        int res=0;
        for(int i=1;i<=m;i++)
            if(cnt[i]!=0)
                res++;
        return res;
    }

};
vector<haha>s,luu,vec;
vector<ii>SS;

int32_t main()
{
   // freopen("A.inp","r",stdin);
  //  freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        s=" "+s;
        for(int j=1;j<=m;j++)
        {
           // a[i][j]=rand()%2;
            a[i][j]=(s[j]-'0');
          ///  cout<<i<<" "<<j<<" "<<a[i][j]<<endl;
        }
    }
    for(int i=1;i<=m;i++)
        f[i]=1ll*rand()*rand()*rand();
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        s.emplace_back();
        s.back().sl=1;
        for(int j=0;j<s.size();j++)
            s[j].build(i);
        SS.clear();
        for(int j=0;j<s.size();j++)
            SS.pb({s[j].val,j});
        sort(SS.begin(),SS.end());
        vec.clear();
        for(int j=0;j<s.size();j++)
             vec.pb(s[SS[j].sc]);
        s=vec;
        luu.clear();
        while(!s.empty())
        {
            haha cc=s.back();
            s.pop_back();
            if(!s.empty()&&s.back().val==cc.val)
            {
                s.back().sum+=cc.sum;
                s.back().sl+=cc.sl;
            }else
            {
                luu.pb(cc);
            }
        }
        s=luu;
        for(auto cc:s)
            ans+=cc.sum+cc.solve()*cc.sl;
    }
    cout<<ans;
    return 0;
}

Compilation message

raspad.cpp: In function 'int32_t main()':
raspad.cpp:121:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<haha>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         for(int j=0;j<s.size();j++)
      |                     ~^~~~~~~~~
raspad.cpp:124:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<haha>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |         for(int j=0;j<s.size();j++)
      |                     ~^~~~~~~~~
raspad.cpp:128:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<haha>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         for(int j=0;j<s.size();j++)
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 9 ms 744 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 34 ms 840 KB Output is correct
10 Correct 8 ms 736 KB Output is correct
11 Correct 19 ms 724 KB Output is correct
12 Correct 26 ms 816 KB Output is correct
13 Correct 26 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 21852 KB Output is correct
2 Correct 243 ms 43384 KB Output is correct
3 Correct 531 ms 43412 KB Output is correct
4 Correct 139 ms 39180 KB Output is correct
5 Correct 75 ms 13268 KB Output is correct
6 Correct 305 ms 43392 KB Output is correct
7 Correct 443 ms 43440 KB Output is correct
8 Correct 228 ms 34792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 9 ms 744 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 34 ms 840 KB Output is correct
10 Correct 8 ms 736 KB Output is correct
11 Correct 19 ms 724 KB Output is correct
12 Correct 26 ms 816 KB Output is correct
13 Correct 26 ms 724 KB Output is correct
14 Correct 90 ms 21852 KB Output is correct
15 Correct 243 ms 43384 KB Output is correct
16 Correct 531 ms 43412 KB Output is correct
17 Correct 139 ms 39180 KB Output is correct
18 Correct 75 ms 13268 KB Output is correct
19 Correct 305 ms 43392 KB Output is correct
20 Correct 443 ms 43440 KB Output is correct
21 Correct 228 ms 34792 KB Output is correct
22 Correct 806 ms 34832 KB Output is correct
23 Correct 3915 ms 43444 KB Output is correct
24 Correct 3739 ms 43448 KB Output is correct
25 Correct 834 ms 43468 KB Output is correct
26 Correct 889 ms 43376 KB Output is correct
27 Correct 1073 ms 43404 KB Output is correct
28 Correct 2672 ms 43444 KB Output is correct
29 Correct 1602 ms 43404 KB Output is correct
30 Correct 567 ms 43264 KB Output is correct
31 Execution timed out 6056 ms 43468 KB Time limit exceeded
32 Halted 0 ms 0 KB -