Submission #18639

#TimeUsernameProblemLanguageResultExecution timeMemory
18639Namnamseo경비원 (GA8_guard)C++14
13 / 100
603 ms21780 KiB
#include <cstdio> #include <algorithm> #include <queue> int ps[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int pn=15; int n; int data[2223]; typedef std::pair<int,int> pp; pp dd[2223]; int dp[1<<15]; int M=int(1e9)+7; int getMaxDivisor(int x){ for(int i=2;i*i<=x;++i) if(x%i==0) return x/i; return x; } int main() { int i,j; scanf("%d",&n); for(i=0;i<n;++i){ scanf("%d",data+i); dd[i]={getMaxDivisor(data[i]),data[i]}; } std::sort(dd,dd+n); dp[0]=1; std::queue<pp> pending; for(i=0;i<n;++i){ int mymask = 0; int myval = dd[i].second; for(j=0; j<pn; ++j) if(myval % ps[j]==0) mymask |= (1<<j); for(j=0; j<32768; ++j){ if((j&mymask) == mymask){ pending.push({j, dp[j^mymask]}); } } if(i+1==n || dd[i].first != dd[i+1].first){ while(pending.size()){ pp& tmp=pending.front(); dp[tmp.first]+=tmp.second; dp[tmp.first]%=M; pending.pop(); } } } int ans=0; for(i=0; i<32768; ++i) ans+=dp[i], ans%=M; printf("%d\n",(ans-n-1+M)%M); return 0; }
#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...