Submission #712115

# Submission time Handle Problem Language Result Execution time Memory
712115 2023-03-18T07:11:53 Z guagua0407 Sateliti (COCI20_satellti) C++17
110 / 110
523 ms 36752 KB
/*
燒雞
 燒雞
  燒雞    好想進選訓
 燒雞
燒雞
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end() 
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
 
const int mxn=1005;
const int MOD=1e9+7;
char S[2*mxn][2*mxn];
ll hashv[2*mxn][2*mxn];
ll powx[2*mxn],powy[2*mxn];
random_device rng;
mt19937_64 seed(rng());
//ll X=abs((ll)seed());
//ll Y=abs((ll)seed());
 
ll X=3;
ll Y=4;
 
void genhash(int n,int m){
    powx[0]=powy[0]=1;
    for(int i=1;i<2*mxn;i++){
        powx[i]=(powx[i-1]*X)%MOD;
    }
    for(int i=1;i<2*mxn;i++){
        powy[i]=(powy[i-1]*Y)%MOD;
    }
    for(int i=1;i<=2*n;i++){
        for(int j=1;j<=2*m;j++){
            hashv[i][j]=(hashv[i][j-1]*X%MOD+S[i][j])%MOD;
        }
    }
    for(int j=1;j<=2*m;j++){
        for(int i=1;i<=2*n;i++){
            hashv[i][j]=(hashv[i-1][j]*Y%MOD+hashv[i][j])%MOD;
        }
    }
}
 
int cal(int a,int b,int xx,int yy){
    int x=a+xx-1;
    int y=b+yy-1;
    ll ans=(hashv[x][y]-hashv[x][b-1]*powx[y-b+1]%MOD-hashv[a-1][y]*powy[x-a+1]%MOD);
    if(ans<0) ans+=MOD;
    ans=(ans+hashv[a-1][b-1]*powy[x-a+1]%MOD*powx[y-b+1])%MOD;
    return ans;
}
 
int main() {_
    //setIO("wayne");
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>S[i][j];
            S[i+n][j]=S[i][j+m]=S[i+n][j+m]=S[i][j];
        }
    }
    genhash(n,m);
    int ansx=1,ansy=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int l=i-1,r=i+n-1;
            while(l<r){
                int mid=(l+r+1)/2;
                if(cal(i,j,mid-i+1,m)==cal(ansx,ansy,mid-i+1,m)){
                    l=mid;
                }
                else{
                    r=mid-1;
                }
            }
            int row=l+1;
            l=j-1;
            r=j+m-1;
            while(l<r){
                int mid=(l+r+1)/2;
                if(cal(row,j,1,mid-j+1)==cal(ansx+(row-i),ansy,1,mid-j+1)){
                    l=mid;
                }
                else{
                    r=mid-1;
                }
            }
            int col=l+1;
            if(row<=i+n-1 and col<=j+m-1){
                if(S[row][col]<S[ansx+(row-i)][ansy+(col-j)]){
                    ansx=i,ansy=j;
                }
            }
        }
    }
    for(int i=ansx;i<=ansx+n-1;i++){
        for(int j=ansy;j<=ansy+m-1;j++){
            cout<<S[i][j];
        }
        cout<<'\n';
    }
    return 0;
}
//maybe its multiset not set

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 992 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 2 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 992 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 2 ms 1020 KB Output is correct
8 Correct 36 ms 6564 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 3924 KB Output is correct
11 Correct 39 ms 6524 KB Output is correct
12 Correct 40 ms 6732 KB Output is correct
13 Correct 43 ms 6856 KB Output is correct
14 Correct 42 ms 6768 KB Output is correct
15 Correct 37 ms 6792 KB Output is correct
16 Correct 41 ms 6768 KB Output is correct
17 Correct 46 ms 6772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 992 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 2 ms 1020 KB Output is correct
8 Correct 36 ms 6564 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 3924 KB Output is correct
11 Correct 39 ms 6524 KB Output is correct
12 Correct 40 ms 6732 KB Output is correct
13 Correct 43 ms 6856 KB Output is correct
14 Correct 42 ms 6768 KB Output is correct
15 Correct 37 ms 6792 KB Output is correct
16 Correct 41 ms 6768 KB Output is correct
17 Correct 46 ms 6772 KB Output is correct
18 Correct 438 ms 36636 KB Output is correct
19 Correct 10 ms 12628 KB Output is correct
20 Correct 8 ms 980 KB Output is correct
21 Correct 414 ms 36752 KB Output is correct
22 Correct 523 ms 36748 KB Output is correct
23 Correct 411 ms 36684 KB Output is correct
24 Correct 489 ms 36668 KB Output is correct
25 Correct 418 ms 36724 KB Output is correct
26 Correct 483 ms 36712 KB Output is correct
27 Correct 514 ms 36608 KB Output is correct