Submission #1692091
Source Code Expand
#include <stdio.h> #include <stdlib.h> #define p (int)(1e9 + 7) //nに含まれる1の数を求める int element_count(int n){ n = (0x55555555 & n) + (0x55555555 & (n >> 1)); n = (0x33333333 & n) + (0x33333333 & (n >> 2)); n = (0x0f0f0f0f & n) + (0x0f0f0f0f & (n >> 4)); n = (0x00ff00ff & n) + (0x00ff00ff & (n >> 8)); n = (0x0000ffff & n) + (0x0000ffff & (n >> 16)); return n; } int can_put(int i, int j){ if(j % 5 != 0 && j % 5 != 4){ if(((i & (1 << (j - 1))) == 0) ^ ((i & (1 << (j + 1))) == 0)){ return 0; } } if(j / 5 != 0 && j / 5 != 4){ if(((i & (1 << (j - 5))) == 0) ^ ((i & (1 << (j + 5))) == 0)){ return 0; } } return 1; } int main(){ int i, j; int *x = (int *)malloc(sizeof(int) * 25); int *pos = (int *)malloc(sizeof(int) * 25); for(i = 0; i < 25; i++){ scanf("%d", &x[i]); x[i]--; pos[i] = -1; } for(i = 0; i < 25; i++){ if(x[i] >= 0){ pos[x[i]] = i; } } int zv25 = 1 << 25; int *dp = (int *)malloc(sizeof(int) * zv25); for(i = 1; i < zv25; i++){ dp[i] = 0; } dp[0] = 1; for(i = 0; i < zv25; i++){ if(pos[element_count(i)] >= 0){ j = pos[element_count(i)]; if((i & (1 << j)) == 0 && can_put(i, j) == 1){ dp[i | (1 << j)] = (dp[i | (1 << j)] + dp[i]) % p; } } else{ for(j = 0; j < 25; j++){ if(x[j] == -1 && (i & (1 << j)) == 0 && can_put(i, j) == 1){ dp[i | (1 << j)] = (dp[i | (1 << j)] + dp[i]) % p; } } } } printf("%d\n", dp[zv25 - 1]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 25個の整数 |
User | abc050 |
Language | C (GCC 5.4.1) |
Score | 100 |
Code Size | 1529 Byte |
Status | AC |
Exec Time | 3264 ms |
Memory | 131200 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:34:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &x[i]); ^
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 30 / 30 | 70 / 70 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt |
Subtask2 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt, test-2-01.txt, test-2-02.txt, test-2-03.txt, test-2-04.txt, test-2-05.txt, test-2-06.txt, test-2-07.txt, test-2-08.txt, test-2-09.txt, test-2-10.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | AC | 963 ms | 131200 KB |
sample-02.txt | AC | 367 ms | 131200 KB |
sample-03.txt | AC | 381 ms | 131200 KB |
sample-04.txt | AC | 318 ms | 131200 KB |
test-1-01.txt | AC | 724 ms | 131200 KB |
test-1-02.txt | AC | 802 ms | 131200 KB |
test-1-03.txt | AC | 975 ms | 131200 KB |
test-1-04.txt | AC | 737 ms | 131200 KB |
test-1-05.txt | AC | 410 ms | 131200 KB |
test-1-06.txt | AC | 1041 ms | 131200 KB |
test-1-07.txt | AC | 1160 ms | 131200 KB |
test-1-08.txt | AC | 564 ms | 131200 KB |
test-1-09.txt | AC | 833 ms | 131200 KB |
test-1-10.txt | AC | 326 ms | 131200 KB |
test-1-11.txt | AC | 393 ms | 131200 KB |
test-1-12.txt | AC | 775 ms | 131200 KB |
test-1-13.txt | AC | 351 ms | 131200 KB |
test-1-14.txt | AC | 687 ms | 131200 KB |
test-1-15.txt | AC | 1229 ms | 131200 KB |
test-2-01.txt | AC | 2233 ms | 131200 KB |
test-2-02.txt | AC | 1569 ms | 131200 KB |
test-2-03.txt | AC | 1513 ms | 131200 KB |
test-2-04.txt | AC | 1760 ms | 131200 KB |
test-2-05.txt | AC | 1991 ms | 131200 KB |
test-2-06.txt | AC | 2934 ms | 131200 KB |
test-2-07.txt | AC | 3156 ms | 131200 KB |
test-2-08.txt | AC | 3264 ms | 131200 KB |
test-2-09.txt | AC | 2750 ms | 131200 KB |
test-2-10.txt | AC | 3245 ms | 131200 KB |