# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
567224 | tqbfjotld | Misspelling (JOI22_misspelling) | C++14 | 157 ms | 8852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int rel[20];
int A[500005];
int B[500005];
int mem[20][26];
int func(int n, int last){
if (mem[n][last]!=-1) return mem[n][last];
if (n==1) return 1;
if (rel[n-2]==1){
return mem[n][last] = func(n-1,last);
}
int ans = 0;
for (int x = 0; x<26; x++){
if (rel[n-2]==0 && last>x){
ans += func(n-1,x);
}
if (rel[n-2]==2 && last<x){
ans += func(n-1,x);
}
ans %= 1000000007;
}
return mem[n][last] = ans;
}
main(){
int n,m;
scanf("%lld%lld",&n,&m);
for (int x = 0; x<m; x++){
scanf("%lld%lld",&A[x],&B[x]);
A[x]--; B[x]--;
}
int ans = 0;
for (int x = 0; x<(int)pow(3,n-1); x++){
int t = x;
for (int y = 0; y<n-1; y++){
rel[y] = t%3;
//printf("%lld ",rel[y]);
t/=3;
}
//printf("\n");
bool can = true;
for (int y = 0; y<m; y++){
if (A[y]<B[y]){
for (int z = 0; z<B[y]-A[y]; z++){
if (rel[A[y]+z]==0){
can = false;
break;
}
if (rel[A[y]+z]==2){
break;
}
}
}
else{
for (int z = 0; z<A[y]-B[y]; z++){
if (rel[B[y]+z]==2){
can = false;
break;
}
if (rel[B[y]+z]==0){
break;
}
}
}
}
if (can){
//printf("hi\n");
memset(mem,-1,sizeof(mem));
for (int x = 0; x<26; x++){
ans += func(n,x);
ans %= 1000000007;
}
}
}
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |