답안 #238692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238692 2020-06-12T11:13:27 Z SamAnd Konstrukcija (COCI20_konstrukcija) C++17
0 / 110
5 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1003;

/*int n, m;
vector<int> a[N];

vector<int> v;
bool cc[N];
void dfs1(int x)
{
    cc[x] = true;
    v.push_back(x);
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (!cc[h])
            dfs1(h);
    }
}

bool c[N];
int k[N], z[N];
void dfs(int x)
{
    c[x] = true;
    if (x == n)
    {
        k[x] = 1;
        return;
    }
    v.clear();
    memset(cc, 0, sizeof cc);
    dfs1(x);
    vector<int> yv = v;
    for (int i = 0; i < yv.size(); ++i)
    {
        int h = yv[i];
        if (h == x)
            continue;
        if (!c[h])
            dfs(h);
        z[x] += k[h];
        k[x] += z[h];
    }
    //printf("%d %d %d\n", x, k[x], z[x]);
}

void por()
{
    //scanf("%d%d", &n, &m);
    scanf("%d", &n);
    int x, y;
    while (scanf("%d%d", &x, &y) != EOF)
    {
        a[x].push_back(y);
    }
    dfs(1);
    printf("%d\n", k[1] - z[1]);
}*/

int n;
vector<pair<int, int> > ans;

ll k;

vector<int> v;

void ave(int x)
{
    k *= -(x - 1);
    vector<int> u;
    for (int i = 0; i < x; ++i)
        u.push_back(++n);
    for (int i1 = 0; i1 < v.size(); ++i1)
    {
        for (int i2 = 0; i2 < u.size(); ++i2)
        {
            ans.push_back(m_p(v[i1], u[i2]));
        }
    }
    v = u;
}

void solv()
{
    scanf("%lld", &k);
    if (k == 0)
    {
        printf("6 6\n");
        printf("1 4\n");
        printf("1 5\n");
        printf("4 3\n");
        printf("5 3\n");
        printf("3 2\n");
        printf("2 6\n");
        return;
    }
    bool z = false;
    if (k < 0)
    {
        z = true;
        k *= -1;
    }
    vector<int> bk;
    while (k)
    {
        bk.push_back(k % 2);
        k /= 2;
    }
    reverse(all(bk));
    k = -1;
    v.push_back(++n);
    for (int i = 0; i < bk.size(); ++i)
    {
        if (bk[i])
        {
            if (k > 0)
                ave(2);
            v.push_back(++n);
            ans.push_back(m_p(1, v.back()));
        }
        if (i != sz(bk) - 1)
            ave(3);
    }
    if ((k > 0 && z) || (k < 0 && !z))
        ave(2);
    ave(1);
    printf("%d %d\n", n, ans.size());
    for (int i = 0; i < ans.size(); ++i)
        printf("%d %d\n", ans[i].fi, ans[i].se);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    //por();
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

konstrukcija.cpp: In function 'void ave(int)':
konstrukcija.cpp:83:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i1 = 0; i1 < v.size(); ++i1)
                      ~~~^~~~~~~~~~
konstrukcija.cpp:85:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i2 = 0; i2 < u.size(); ++i2)
                          ~~~^~~~~~~~~~
konstrukcija.cpp: In function 'void solv()':
konstrukcija.cpp:122:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < bk.size(); ++i)
                     ~~^~~~~~~~~~~
konstrukcija.cpp:137:36: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d %d\n", n, ans.size());
                          ~~~~~~~~~~^
konstrukcija.cpp:138:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); ++i)
                     ~~^~~~~~~~~~~~
konstrukcija.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &k);
     ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Wrong answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Wrong answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Wrong answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Wrong answer.
2 Halted 0 ms 0 KB -