답안 #132778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132778 2019-07-19T14:23:34 Z Just_Solve_The_Problem Skyscraper (JOI16_skyscraper) C++11
0 / 100
752 ms 97548 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e2 + 7;
const int mod = (int)1e9 + 7;

int add(int a, int b) {
  return (a + b) % mod;
}

int mul(int a, int b) {
  return (a * 1LL * b) % mod;
}

int n, l;
int a[N];
int dp[1 << 14][101][15];

int go(int mask, int lst, int sum) {
  if (mask == 0) return 1;
  int &res = dp[mask][sum][lst];
  if (res != -1) return res;
  res = 0;
  for (int i = 0; i < n; i++) {
    if ((mask >> i) & 1 ^ 1) continue;
    int cost = abs(a[lst] - a[i]);
    if (lst == n) cost = 0;
    if (sum + cost <= l)
      res += go(mask ^ (1 << i), i, sum + cost);
  }
  return res;
}

main() {
  memset(dp, -1, sizeof dp);
  scanf("%d %d", &n, &l);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (n > 14) 
    return 0;
  printf("%d\n", go((1 << n) - 1, n, 0));
}

Compilation message

skyscraper.cpp: In function 'int go(int, int, int)':
skyscraper.cpp:26:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     if ((mask >> i) & 1 ^ 1) continue;
         ~~~~~~~~~~~~^~~
skyscraper.cpp: At global scope:
skyscraper.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &l);
   ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a[i]);
     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 97528 KB Output is correct
2 Correct 81 ms 97480 KB Output is correct
3 Correct 80 ms 97528 KB Output is correct
4 Correct 80 ms 97528 KB Output is correct
5 Correct 81 ms 97400 KB Output is correct
6 Correct 81 ms 97392 KB Output is correct
7 Correct 81 ms 97400 KB Output is correct
8 Correct 82 ms 97528 KB Output is correct
9 Incorrect 82 ms 97400 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 97528 KB Output is correct
2 Correct 119 ms 97528 KB Output is correct
3 Correct 526 ms 97548 KB Output is correct
4 Correct 118 ms 97528 KB Output is correct
5 Correct 129 ms 97400 KB Output is correct
6 Correct 703 ms 97528 KB Output is correct
7 Correct 106 ms 97400 KB Output is correct
8 Correct 495 ms 97520 KB Output is correct
9 Incorrect 752 ms 97548 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 97528 KB Output is correct
2 Correct 81 ms 97480 KB Output is correct
3 Correct 80 ms 97528 KB Output is correct
4 Correct 80 ms 97528 KB Output is correct
5 Correct 81 ms 97400 KB Output is correct
6 Correct 81 ms 97392 KB Output is correct
7 Correct 81 ms 97400 KB Output is correct
8 Correct 82 ms 97528 KB Output is correct
9 Incorrect 82 ms 97400 KB Output isn't correct
10 Halted 0 ms 0 KB -