Submission #1014512

# Submission time Handle Problem Language Result Execution time Memory
1014512 2024-07-05T04:56:23 Z User0069 Sateliti (COCI20_satellti) C++17
110 / 110
724 ms 80724 KB
#include<bits/stdc++.h>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=1e5+3;
const int mod=1e9+7;
const int INF=1e9+1;
int n,m,a[2005][2005],pfs[2005][2005],po[2005*2005],inv[2005*2005];
int p(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int get(int a,int b,int c,int d)
{
    if(c<a||d<b) return 0;
    return (pfs[c][d]-pfs[c][b-1]-pfs[a-1][d]+pfs[a-1][b-1]+3*mod)%mod;
}
int get1(int i,int j,int k)
{
    int cc=0;
    cc+=get(i,j,i+k/m -1,j+m-1);
//    cout<<cc<<"\n";
    cc+=get(i+k/m,j,i+k/m,j+k%m-1);
//    cout<<cc<<"\n";
    cc%=mod;
    cc*=inv[(i-1)*m+j];
    cc%=mod;
    return cc;
}
signed main()
{
    if (fopen(taskname".INP","r"))
    {
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    Faster
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            char x;
            cin>>x;
            if(x=='.') a[i][j]=2;
            else a[i][j]=1;
            a[i+n][j]=a[i][j+m]=a[i+n][j+m]=a[i][j];
        }
    }
    po[0]=1;
    inv[0]=1;
    for(int i=1;i<=n*m;i++)
    {
        po[i]=po[i-1]*31%mod;
        inv[i]=p(po[i],mod-2);
    }
    for(int i=1;i<=2*n;i++)
    {
        for(int j=1;j<=2*m;j++)
        {
            pfs[i][j]=(pfs[i-1][j]+pfs[i][j-1]-pfs[i-1][j-1]+a[i][j]*po[(i-1)*m+j]+3*mod)%mod;
        }
    }
    int bi=1,bj=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int l=1,r=n*m,res=-1;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(get1(i,j,mid)!=get1(bi,bj,mid))
                {
                    res=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
//            cout<<i<<" "<<j<<" "<<bi<<" "<<bj<<" "<<res<<"\n";
            int ii,jj;
            if(res==-1) continue;
            if(res%m==0)
            {
                ii=res/m-1;
                jj=m-1;
            }
            else
            {
                ii=res/m;
                jj=res%m-1;
            }
//            cout<<i+ii<<" "<<j+jj<<" "<<bi+ii<<" "<<bj+jj<<"!\n";
            if(a[i+ii][j+jj]<a[bi+ii][bj+jj])
            {
                bi=i;
                bj=j;
            }

        }
    }
    for(int i=bi;i<bi+n;i++)
    {
        for(int j=bj;j<bj+m;j++)
        {
            if(a[i][j]==1) cout<<'*';
            else cout<<'.';
        }
        cout<<"\n";
    }
//    cout<<get1(1,2,1)<<" "<<get1(1,1,1);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 2 ms 1232 KB Output is correct
5 Correct 2 ms 1368 KB Output is correct
6 Correct 1 ms 1240 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 2 ms 1232 KB Output is correct
5 Correct 2 ms 1368 KB Output is correct
6 Correct 1 ms 1240 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 46 ms 12116 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 5280 KB Output is correct
11 Correct 44 ms 12040 KB Output is correct
12 Correct 53 ms 12124 KB Output is correct
13 Correct 47 ms 12420 KB Output is correct
14 Correct 53 ms 12376 KB Output is correct
15 Correct 49 ms 12272 KB Output is correct
16 Correct 63 ms 12420 KB Output is correct
17 Correct 55 ms 12420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 2 ms 1232 KB Output is correct
5 Correct 2 ms 1368 KB Output is correct
6 Correct 1 ms 1240 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 46 ms 12116 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 5280 KB Output is correct
11 Correct 44 ms 12040 KB Output is correct
12 Correct 53 ms 12124 KB Output is correct
13 Correct 47 ms 12420 KB Output is correct
14 Correct 53 ms 12376 KB Output is correct
15 Correct 49 ms 12272 KB Output is correct
16 Correct 63 ms 12420 KB Output is correct
17 Correct 55 ms 12420 KB Output is correct
18 Correct 572 ms 80724 KB Output is correct
19 Correct 10 ms 17240 KB Output is correct
20 Correct 8 ms 2004 KB Output is correct
21 Correct 520 ms 80704 KB Output is correct
22 Correct 673 ms 80672 KB Output is correct
23 Correct 617 ms 80720 KB Output is correct
24 Correct 724 ms 80664 KB Output is correct
25 Correct 652 ms 80720 KB Output is correct
26 Correct 658 ms 80720 KB Output is correct
27 Correct 712 ms 80720 KB Output is correct