제출 #339631

#제출 시각아이디문제언어결과실행 시간메모리
339631Ahmad_Hasan아름다운 순열 (IZhO12_beauty)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; int n; int nums[25]; int cnt=0; vector<vector<int> > dp; int slv(int msk=0,int lstidx=-1){ if(msk==(1<<n)-1){ return 1; } int cnt=0; if(lstidx!=-1&&dp[msk][lstidx]!=-1) return dp[msk][lstidx]; for(int i=0;i<n;i++){ if(!(msk&(1<<i))){ if(lstidx==-1){ cnt+=slv(msk|(1<<i),i); continue; } int f=0; { int num1=nums[lstidx]; int num2=nums[i]; int cntb2=0; while(num1||num2){ cntb2-=num1%2; cntb2+=num2%2; num1/=2; num2/=2; } if(!cntb2){ f=1; } num1=nums[lstidx]; num2=nums[i]; int cntb3=0; while(num1||num2){ cntb3-=num1%3==1; cntb3+=num2%3==1; num1/=3; num2/=3; } if(!cntb3){ f=1; } } if(f){ cnt+=slv(msk|(1<<i),i); } } } return dp[msk][lstidx]=cnt; } int main() { freopen("stdin.in","r",stdin); freopen("stdout.out","w",stdout); cin>>n; for(int i=0;i<n;i++){ cin>>nums[i]; } dp=vector<vector<int> >((1<<n)+5,vector<int>(n+5,-1)); cout<<slv(); return 0; } /**** 1 8 4 3 1 4 3 1 8 8 7 1 100 9 1 100 2 1 3 2 4 3 5 4 100 99 99 98 98 97 97 96 19 3 6 3 12 9 2000000000 1000000000 1000000000 3 1000000000 1000000000 */

컴파일 시 표준 에러 (stderr) 메시지

beauty.cpp: In function 'int main()':
beauty.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     freopen("stdin.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
beauty.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     freopen("stdout.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...