답안 #164235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164235 2019-11-18T17:58:08 Z aggu_01000101 Ispit (COCI19_ispit) C++14
18 / 90
535 ms 65540 KB
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <fstream>
#include <set>
#include <iomanip>
#include <unordered_map>
#define INF 1e16
#define int long long
#define N (int)1e5 + 5
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);
    int n, m;
    cin>>n>>m;
    char mat[n][n];
    int maxpref[n][n];
    int maxsuff[n][n];
    int freq[n][n][26];
    for(int i = 0;i<n;i++){
        string s;
        cin>>s;
        for(int j =0 ;j<s.length();j++){
            mat[i][j] = s[j];
        }
    }
    for(int i = 0;i<n;i++){
        for(int j =0 ;j<n;j++){
            for(int k = 0;k<26;k++){
                freq[i][j][k] = 0;
            }
        }
    }
    for(int i = 0;i<n;i++){
        freq[i][0][mat[i][0] - 'a']=1;
        for(int j = 1;j<n;j++){
            for(int k = 0;k<26;k++){
                freq[i][j][k]=freq[i][j-1][k];
            }
            freq[i][j][mat[i][j]-'a']++;
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            maxpref[i][j] = maxsuff[i][j] = 0;
            int k = -1;
            while(++k<n && mat[i][k]==mat[j][k]) ++maxpref[i][j];
            k = n;
            while(--k>=0 && mat[i][k]==mat[j][k]) ++maxsuff[i][j];
        }
    }
    int cnt[26], cnt1[26];
    bool possible = false;
    for(int i = 0;i<n;i++){
        for(int k = i+1;k<n;k++){
            for(int l = 0;l<26;l++) cnt[i] = cnt1[i] = 0;
            int samecount = 26;
            for(int j = 0;j<m;j++){
                if(mat[i][j] != mat[k][j] && cnt[mat[i][j]-'a'] == cnt1[mat[i][j]-'a']) samecount--;
                cnt[mat[i][j]-'a']++;
                if(mat[i][j] != mat[k][j] && cnt[mat[k][j]-'a'] == cnt1[mat[k][j]-'a']) samecount--;
                cnt1[mat[k][j]-'a']++;
                if(mat[i][j] != mat[k][j] && cnt[mat[i][j]-'a'] == cnt1[mat[i][j]-'a']) samecount++;
                if(mat[i][j] != mat[k][j] && cnt[mat[k][j]-'a'] == cnt1[mat[k][j]-'a']) samecount++;
            }
            if(samecount==26 && maxsuff[i][k]>=(n-m)) possible = true;
            for(int j = m;j<n;j++){
                if(mat[i][j-m] != mat[k][j-m] && cnt[mat[i][j-m]-'a'] == cnt1[mat[i][j-m]-'a']) samecount--;
                cnt[mat[i][j-m]-'a']--;
                if(mat[i][j-m] != mat[k][j-m] && cnt1[mat[k][j-m]-'a'] == cnt[mat[k][j-m]-'a']) samecount--;
                cnt1[mat[k][j-m]-'a']--;
                if(mat[i][j] != mat[k][j] && cnt[mat[i][j]-'a'] == cnt1[mat[i][j]-'a']) samecount--;
                cnt[mat[i][j]-'a']++;
                if(mat[i][j] != mat[k][j] && cnt[mat[k][j]-'a'] == cnt1[mat[k][j]-'a']) samecount--;
                cnt1[mat[k][j]-'a']++;
                if(mat[i][j] != mat[k][j] && cnt[mat[i][j]-'a'] == cnt1[mat[i][j]-'a']) samecount++;
                if(mat[i][j] != mat[k][j] && cnt[mat[k][j]-'a'] == cnt1[mat[k][j]-'a']) samecount++;
                if(samecount==26 && maxsuff[i][k]>=(n-j-1) && maxpref[i][k]>=(j-m+1)) possible = true;
                //cout<<i<<" "<<k<<" "<<samecount<<endl;
            }
        }
    }
    for(int i = 0;i<(n-1);i++){
        for(int l = i+1;l<n;l++) {
            if (maxpref[i][l]==n) possible = true;
        }
    }
    if(possible) cout<<"DA"<<endl;
    else cout<<"NE"<<endl;
}

Compilation message

ispit.cpp: In function 'int32_t main()':
ispit.cpp:26:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j =0 ;j<s.length();j++){
                       ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 18296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 56 ms 18424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 18300 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 18300 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 485 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 535 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 454 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -