답안 #712117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712117 2023-03-18T07:13:54 Z guagua0407 Sateliti (COCI20_satellti) C++17
110 / 110
484 ms 36792 KB
/*
燒雞
 燒雞
  燒雞    好想進選訓
 燒雞
燒雞
*/
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 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 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 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 980 KB Output is correct
8 Correct 37 ms 6612 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 36 ms 6564 KB Output is correct
12 Correct 40 ms 6700 KB Output is correct
13 Correct 37 ms 6800 KB Output is correct
14 Correct 41 ms 6772 KB Output is correct
15 Correct 39 ms 6772 KB Output is correct
16 Correct 39 ms 6788 KB Output is correct
17 Correct 42 ms 6772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 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 980 KB Output is correct
8 Correct 37 ms 6612 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 36 ms 6564 KB Output is correct
12 Correct 40 ms 6700 KB Output is correct
13 Correct 37 ms 6800 KB Output is correct
14 Correct 41 ms 6772 KB Output is correct
15 Correct 39 ms 6772 KB Output is correct
16 Correct 39 ms 6788 KB Output is correct
17 Correct 42 ms 6772 KB Output is correct
18 Correct 457 ms 36608 KB Output is correct
19 Correct 10 ms 12628 KB Output is correct
20 Correct 8 ms 1056 KB Output is correct
21 Correct 425 ms 36724 KB Output is correct
22 Correct 483 ms 36652 KB Output is correct
23 Correct 412 ms 36792 KB Output is correct
24 Correct 480 ms 36756 KB Output is correct
25 Correct 413 ms 36644 KB Output is correct
26 Correct 472 ms 36648 KB Output is correct
27 Correct 484 ms 36612 KB Output is correct