Submission #13914

#TimeUsernameProblemLanguageResultExecution timeMemory
13914gs14004경비원 (GA8_guard)C++14
21 / 100
152 ms1372 KiB
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int mod = 1e9 + 7; int n; int pr[15] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; struct num{ int val; int lowbit; int rem; }a[2005]; bool cmp(num a, num b){return a.rem < b.rem;} void input(){ scanf("%d",&n); for (int i=1; i<=n; i++) { scanf("%d",&a[i].val); int t = a[i].val; for (int j=0; j<15; j++) { while(t % pr[j] == 0){ a[i].lowbit |= 1<<j; t /= pr[j]; } } a[i].rem = t; } sort(a+1,a+n+1,cmp); } int dp[2][1<<15]; int main(){ input(); dp[0][0] = 1; int back[1<<15]; for (int i=1; i<=n; i++) { if(a[i].rem == 1){ for (int j=0; j<(1<<15); j++) { dp[i%2][j] = 0; if((a[i].lowbit & ~j) == 0){ dp[i%2][j] = dp[(i-1)%2][j ^ a[i].lowbit]; } dp[i%2][j] += dp[(i-1)%2][j]; dp[i%2][j] %= mod; } } else{ if(a[i].rem != a[i-1].rem){ memcpy(back,dp[(i-1)%2],sizeof(back)); } for (int j=0; j<(1<<15); j++) { dp[i%2][j] = 0; if((a[i].lowbit & ~j) == 0){ dp[i%2][j] = back[j ^ a[i].lowbit]; } dp[i%2][j] += dp[(i-1)%2][j]; dp[i%2][j] %= mod; } } } int ret = mod - n - 1; for (int i=0; i<(1<<15); i++) { ret += dp[n%2][i]; ret %= mod; } printf("%d",ret); }
#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...