Submission #445153

# Submission time Handle Problem Language Result Execution time Memory
445153 2021-07-16T16:28:17 Z Wasif_Jamil Trener (COCI20_trener) C++14
55 / 110
2000 ms 6860 KB
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
 
#include<bits/stdc++.h>
using namespace std; 
const int mod = 1e9 + 7;

bool is(string a, string b){
    char x = a.back();
    a.pop_back();
    if(a == b){
        return 1;
    }
    a.push_back(x);
    a.erase(a.begin());
    if(a == b){
        return 1;
    }
    return 0;
}

void add_self(int &a, int b){
    a += b;
    if(a >= mod){
        a -= mod;
    }
}

int main(){
    int n, m; cin >> n >> m;
    vector<vector<string>>v(n+1, vector<string>(m+1));
    vector<vector<int>>dp(n+1, vector<int>(m+1));
    for(int i=1;i<=n; i++){
        for(int j=1; j<=m; j++){
            cin >> v[i][j];
            if(i == n){
                dp[i][j] = 1;
            }
        }
    }
    for(int i=n-1; i>=1; i--){
        for(int j=1; j<=m; j++){
            for(int x=1; x<=m; x++){
                if(is(v[i+1][x], v[i][j])){
                    add_self(dp[i][j], dp[i+1][x]);
                } 
            }
        }
    }
    int sum = 0;
    for(int i=1; i<=m; i++){
        add_self(sum, dp[1][i]);
    }
    cout << sum << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 824 KB Output is correct
2 Correct 51 ms 808 KB Output is correct
3 Correct 51 ms 816 KB Output is correct
4 Correct 42 ms 716 KB Output is correct
5 Correct 51 ms 820 KB Output is correct
6 Correct 50 ms 716 KB Output is correct
7 Correct 41 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 49 ms 824 KB Output is correct
6 Correct 51 ms 808 KB Output is correct
7 Correct 51 ms 816 KB Output is correct
8 Correct 42 ms 716 KB Output is correct
9 Correct 51 ms 820 KB Output is correct
10 Correct 50 ms 716 KB Output is correct
11 Correct 41 ms 812 KB Output is correct
12 Execution timed out 2072 ms 6860 KB Time limit exceeded
13 Halted 0 ms 0 KB -