Submission #859759

#TimeUsernameProblemLanguageResultExecution timeMemory
859759alexia_726NoM (RMI21_nom)C++14
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> using namespace std; int n,st[1000000], v[100005], m, cnt, ok; void tipar(int p) { ok=0; for (int i=1;i<p;i++) { if((v[st[i]]!=v[st[2*i]])&&(abs(v[st[i]]-v[st[i]+1])==1)) ok=1; for(int j=i+1;j<=p && ok;j+=(i+1)) if((v[st[j]]-v[st[i]])%m==0) ok=0; } if(ok) cnt++; } int valid(int p) { for (int i=1;i<p;i++) if (st[p]==st[i]) return 0; return 1; } void bec(int p) { for (int k=1;k<=2*n;k++) { st[p]=k; if (valid(p)) if (p==2*n) tipar(p); else bec(p+1); } } int main() { cin>>n>>m; cnt=0; for(int i=1;i<=2*n;++i) { if(i>n) v[i]=i/2; else v[i]=i; } bec(1); cout<<cnt; }

Compilation message (stderr)

Main.cpp: In function 'void bec(int)':
Main.cpp:40:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   40 |         if (valid(p))
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...