Submission #164224

# Submission time Handle Problem Language Result Execution time Memory
164224 2019-11-18T17:02:44 Z aggu_01000101 Ispit (COCI19_ispit) C++14
9 / 90
2000 ms 55544 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];
    for(int i = 0;i<n;i++){
        string s;
        cin>>s;
        for(int j =0 ;j<s.length();j++){
            mat[i][j] = s[j];
        }
    }
    int freq[n][n][26];
    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 j = i+1;j<n;j++){
            maxpref[i][j] = maxpref[j][i] = maxsuff[j][i] = maxsuff[i][j] = 0;
            int k = -1;
            while(++k<n && mat[i][k]==mat[j][k]) maxpref[i][j] = ++maxpref[j][i];
            k = n;
            while(--k>=0 && mat[i][k]==mat[j][k]) maxsuff[i][j] = ++maxsuff[j][i];
        }
    }
    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']++;
        }
    }
    bool possible = false;
    for(int i = 0;i<=(n-m);i++){
        int last = i+m-1;
        for(int j = 0;j<(n-1);j++){
            for(int l = j+1;l<n;l++) {
                bool firstsame = true;
                bool lastsame = true;
                bool charcountsame = true;
                if(maxpref[j][l]<(i+1)) firstsame = false;
                if(maxsuff[j][l]<(n-last-1)) lastsame = false;
                for (int k = 0; k < 26; k++) {
                    int count1 = freq[j][last][k] - i == 0 ? 0 : freq[j][i - 1][k];
                    int count2 = freq[l][last][k] - i == 0 ? 0 : freq[l][i - 1][k];
                    if (count1 != count2) charcountsame = false;
                }
                if (firstsame && lastsame && charcountsame) possible = true;
            }
        }
    }
    for(int i = 0;i<(n-1);i++){
        for(int l = i+1;l<n;l++) {
            bool same = true;
            for (int j = 0; j < n; j++) {
                if (mat[i][j] != mat[l][j]) same = false;
            }
            if (same) possible = true;
        }
    }
    if(possible) cout<<"DA"<<endl;
    else cout<<"NE"<<endl;
}

Compilation message

ispit.cpp: In function 'int32_t main()':
ispit.cpp:25:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j =0 ;j<s.length();j++){
                       ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 9336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9208 KB Output is correct
2 Incorrect 42 ms 9080 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 9080 KB Output is correct
2 Correct 27 ms 9080 KB Output is correct
3 Correct 74 ms 9208 KB Output is correct
4 Incorrect 79 ms 9184 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 9188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 235 ms 55304 KB Output is correct
2 Incorrect 310 ms 55400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 233 ms 55288 KB Output is correct
2 Correct 152 ms 55544 KB Output is correct
3 Execution timed out 2052 ms 55288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 55416 KB Output isn't correct
2 Halted 0 ms 0 KB -