Submission #3303439

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a) int((a).size())
#define pb push_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n)               \
  for (int vari = 0; vari < (n)-1; ++vari) \
    for (int varj = vari + 1; varj < (n); ++varj)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair

ll gcd(ll a, ll b) {
  while (a) swap(a, b %= a);
  return b;
}

bool solve(vi& a) {
  int n = a.size()-1;
    if (a[n] == 1) return false;
    if (a[1] == 0) return false;
    rep1(i, n - 1) if (a[i] != a[n - i]) return false;

    vector<ii> conn;

    int h = n / 2;
    int pre = 1, last_good = 1;
    for (int i=2; i<=n; ++i) {
#ifdef DEBUG
        fprintf(stderr, "a[%d] = %d\n", i, a[i]);
#endif
        conn.pb(ii(pre, i));
        if (last_good >= 0) {
          pre = last_good + 1;
          last_good = -1;
        }
        if (i<=h && a[i]) {
          last_good = i;
        }
    }

    for (ii p: conn) {
        printf("%d %d\n", p.first, p.second);
    }
    return true;
}

#define N_MAX 100000

int main() {
  char buf[N_MAX + 3];
  fgets(buf, N_MAX + 3, stdin);

  vi a;
  a.reserve(N_MAX+1);
  a.pb(0);
  rep(i, N_MAX + 1) {
    if (buf[i] < '0') {
      buf[i] = 0;
      break;
    }
    a.pb(buf[i] - '0');
  }
#ifdef DEBUG
  cerr << a << endl;
#endif

  if (!solve(a)) {
      cout << -1 << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task E - Tr/ee
User naoya_t
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2411 Byte
Status
Exec Time 16 ms
Memory 2804 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:83:31: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(buf, N_MAX + 3, stdin);
                               ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1_1111.txt, sample2_1110.txt, sample3_1010.txt
All 700 / 700 00-0.txt, 000.txt, 11-1.txt, 110.txt, bin.txt, bins.txt, fib.txt, one_0.txt, one_1.txt, one_2.txt, one_3.txt, rndNO1.txt, rndNO_0.txt, rndNO_1.txt, rndNO_2.txt, rndNO_3.txt, rndNO_4.txt, rndNO_5.txt, rndNOeven.txt, rndNOn.txt, rndNOodd.txt, rndYESeven_0.txt, rndYESeven_1.txt, rndYESeven_2.txt, rndYESeven_3.txt, rndYESeven_4.txt, rndYESeven_5.txt, rndYESeven_6.txt, rndYESeven_7.txt, rndYESeven_8.txt, rndYESeven_9.txt, rndYESodd_0.txt, rndYESodd_1.txt, rndYESodd_2.txt, rndYESodd_3.txt, rndYESodd_4.txt, rndYESodd_5.txt, rndYESodd_6.txt, rndYESodd_7.txt, rndYESodd_8.txt, rndYESodd_9.txt, sample1_1111.txt, sample2_1110.txt, sample3_1010.txt, star_0.txt, star_1.txt, star_2.txt, star_3.txt
Case Name Status Exec Time Memory
00-0.txt 2 ms 768 KB
000.txt 1 ms 256 KB
11-1.txt 2 ms 768 KB
110.txt 1 ms 256 KB
bin.txt 11 ms 1912 KB
bins.txt 1 ms 256 KB
fib.txt 16 ms 2676 KB
one_0.txt 16 ms 2804 KB
one_1.txt 16 ms 2804 KB
one_2.txt 16 ms 2804 KB
one_3.txt 16 ms 2804 KB
rndNO1.txt 2 ms 768 KB
rndNO_0.txt 1 ms 256 KB
rndNO_1.txt 1 ms 256 KB
rndNO_2.txt 1 ms 256 KB
rndNO_3.txt 1 ms 256 KB
rndNO_4.txt 1 ms 256 KB
rndNO_5.txt 1 ms 256 KB
rndNOeven.txt 1 ms 512 KB
rndNOn.txt 1 ms 640 KB
rndNOodd.txt 2 ms 768 KB
rndYESeven_0.txt 1 ms 256 KB
rndYESeven_1.txt 1 ms 256 KB
rndYESeven_2.txt 2 ms 384 KB
rndYESeven_3.txt 1 ms 256 KB
rndYESeven_4.txt 2 ms 512 KB
rndYESeven_5.txt 6 ms 1148 KB
rndYESeven_6.txt 1 ms 256 KB
rndYESeven_7.txt 1 ms 256 KB
rndYESeven_8.txt 1 ms 256 KB
rndYESeven_9.txt 1 ms 256 KB
rndYESodd_0.txt 1 ms 256 KB
rndYESodd_1.txt 6 ms 1144 KB
rndYESodd_2.txt 1 ms 256 KB
rndYESodd_3.txt 1 ms 256 KB
rndYESodd_4.txt 1 ms 256 KB
rndYESodd_5.txt 1 ms 256 KB
rndYESodd_6.txt 1 ms 256 KB
rndYESodd_7.txt 3 ms 640 KB
rndYESodd_8.txt 1 ms 256 KB
rndYESodd_9.txt 1 ms 256 KB
sample1_1111.txt 1 ms 256 KB
sample2_1110.txt 1 ms 256 KB
sample3_1010.txt 1 ms 256 KB
star_0.txt 16 ms 2420 KB
star_1.txt 16 ms 2420 KB
star_2.txt 16 ms 2420 KB
star_3.txt 16 ms 2548 KB