답안 #737042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737042 2023-05-06T13:48:46 Z mjhmjh1104 Present (RMI21_present) C++17
0 / 100
4000 ms 8552 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int gcd(int x, int y) {
    if (!x || !y) return x + y;
    return x % y ? gcd(y, x % y) : y;
}

int g[26][26];

bool validate(const int &v) {
    for (int i = 0; i < 25; i++) if (v & 1 << i) for (int j = i + 1; j < 25; j++) if (v & 1 << j) {
        int k = g[i + 1][j + 1] - 1;
        if (~v & 1 << k) return false;
    }
    return true;
}

int t, k;
vector<int> lt;

int main() {
    for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) g[i][j] = gcd(i, j);
    for (int i = 0; i < 1 << 25; i++) {
        if (!validate(i)) continue;
        lt.push_back(i);
    }
    sort(lt.begin(), lt.end(), [](const int &x, const int &y) {
        for (int i = 24; i >= 0; i--) if ((x & 1 << i) != (y & 1 << i)) return (x & 1 << i) < (y & 1 << i);
        return false;
    });
    for (scanf("%d", &t); t--; ) {
        scanf("%d", &k);
        int &c = lt[k];
        vector<int> v;
        for (int i = 0; i < 25; i++) if (c & 1 << i) v.push_back(i + 1);
        printf("%d ", (int)v.size());
        for (auto &i: v) printf("%d ", i);
        puts("");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     for (scanf("%d", &t); t--; ) {
      |          ~~~~~^~~~~~~~~~
Main.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d", &k);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8552 KB Time limit exceeded
2 Halted 0 ms 0 KB -