답안 #834995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834995 2023-08-23T05:01:14 Z rahulverma 아름다운 순열 (IZhO12_beauty) Java 11
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <cstring>
#include <sstream>
#include <fstream>
using namespace std;

const int N = 100;
long long a[N];
long long b[N];
long long dp[1 << 20][23];
int n;

long long rec(long long mask, int last) {
    if (mask == ((1 << n) - 1)) return 1;

    if (last != -1 && dp[mask][last] != -1) return dp[mask][last];
    long long an = 0;
    for (int i = 0; i < n; i++) {
        if ((mask & (1 << i)) == 0) {
            if (last == -1 || a[last] == a[i] || b[last] == b[i]) {
                an += rec(mask | (1 << i), i);
            }
        }
    }
    if (last != -1) dp[mask][last] = an;
    return an;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int i;
    long long ans = 0;

    cin >> n;
    for (i = 0; i < n; i++) {
        long long p;
        cin >> p;
        a[i] = __builtin_popcountll(p);
        long long p1 = p;
        while (p1 > 0) {
            if (p1 % 3 == 1) b[i]++;
            p1 /= 3;
        }
    }

    memset(dp, -1, sizeof(dp));
    ans += rec(0, -1);

    cout << ans << "\n";

    return 0;
}

long long pow(int i) {
    long long ans = 1;
    while (i > 0) {
        ans *= 2;
        i--;
    }
    return ans;
}

Compilation message

beauty.java:1: error: illegal character: '#'
#include <iostream>
^
beauty.java:1: error: class, interface, or enum expected
#include <iostream>
         ^
beauty.java:2: error: illegal character: '#'
#include <vector>
^
beauty.java:3: error: illegal character: '#'
#include <cstring>
^
beauty.java:4: error: illegal character: '#'
#include <sstream>
^
beauty.java:5: error: illegal character: '#'
#include <fstream>
^
beauty.java:8: error: class, interface, or enum expected
const int N = 100;
^
beauty.java:9: error: class, interface, or enum expected
long long a[N];
^
beauty.java:10: error: class, interface, or enum expected
long long b[N];
^
beauty.java:11: error: class, interface, or enum expected
long long dp[1 << 20][23];
^
beauty.java:12: error: class, interface, or enum expected
int n;
^
beauty.java:14: error: class, interface, or enum expected
long long rec(long long mask, int last) {
^
beauty.java:17: error: class, interface, or enum expected
    if (last != -1 && dp[mask][last] != -1) return dp[mask][last];
    ^
beauty.java:18: error: class, interface, or enum expected
    long long an = 0;
    ^
beauty.java:19: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
    ^
beauty.java:19: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
beauty.java:19: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
beauty.java:23: error: class, interface, or enum expected
            }
            ^
beauty.java:27: error: class, interface, or enum expected
    return an;
    ^
beauty.java:28: error: class, interface, or enum expected
}
^
beauty.java:32: error: class, interface, or enum expected
    cin.tie(nullptr);
    ^
beauty.java:34: error: class, interface, or enum expected
    int i;
    ^
beauty.java:35: error: class, interface, or enum expected
    long long ans = 0;
    ^
beauty.java:37: error: class, interface, or enum expected
    cin >> n;
    ^
beauty.java:38: error: class, interface, or enum expected
    for (i = 0; i < n; i++) {
    ^
beauty.java:38: error: class, interface, or enum expected
    for (i = 0; i < n; i++) {
                ^
beauty.java:38: error: class, interface, or enum expected
    for (i = 0; i < n; i++) {
                       ^
beauty.java:40: error: class, interface, or enum expected
        cin >> p;
        ^
beauty.java:41: error: class, interface, or enum expected
        a[i] = __builtin_popcountll(p);
        ^
beauty.java:42: error: class, interface, or enum expected
        long long p1 = p;
        ^
beauty.java:43: error: class, interface, or enum expected
        while (p1 > 0) {
        ^
beauty.java:45: error: class, interface, or enum expected
            p1 /= 3;
            ^
beauty.java:46: error: class, interface, or enum expected
        }
        ^
beauty.java:50: error: class, interface, or enum expected
    ans += rec(0, -1);
    ^
beauty.java:52: error: class, interface, or enum expected
    cout << ans << "\n";
    ^
beauty.java:54: error: class, interface, or enum expected
    return 0;
    ^
beauty.java:55: error: class, interface, or enum expected
}
^
beauty.java:59: error: class, interface, or enum expected
    while (i > 0) {
    ^
beauty.java:61: error: class, interface, or enum expected
        i--;
        ^
beauty.java:62: error: class, interface, or enum expected
    }
    ^
beauty.java:64: error: class, interface, or enum expected
}
^
41 errors