Submission #7868354


Source Code Expand

Copy
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vvi G(n);
  rep(i,n){
    string s;cin>>s;
    rep(j, i+1, n){
      if (s[j]=='1') {
        G[i].pb(j);
        G[j].pb(i);
      }
    }
  }
  dump(G);

  int ans = -1;
  rep(sv, n){
    vi used(n);
    stack<int> st;
    int k = 0;
    st.push(sv);
    bool valid = true;
    vi level(n);

    while(true){
      stack<int> nst;
      k++;
      while(!st.empty()){
        int v = st.top();st.pop();
        level[v] = k;
        used[v] = 1;
        level[v] = k;
        each(to, G[v]){
          if (used[to]==0){
            nst.push(to);
          }
        }
      }
      if (nst.empty()) break;
      else{
        st = nst;
      }
    }
    dump(level);
    rep(i,n){
      each(j, G[i]){
        if (level[i]-level[j]!=1 and level[i]-level[j]!=-1)
          valid = false;
      }
    }
    if (valid) chmax(ans, k);
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}

Submission Info

Submission Time
Task B - Graph Partition
User kjnh10
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2698 Byte
Status TLE
Exec Time 2253 ms
Memory 1646052 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 42
TLE × 13
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 18 ms 384 KB
02.txt AC 23 ms 764 KB
03.txt AC 15 ms 384 KB
04.txt TLE 2253 ms -1670808 KB
05.txt TLE 2149 ms 777780 KB
06.txt TLE 2154 ms 834700 KB
07.txt AC 7 ms 256 KB
08.txt AC 12 ms 384 KB
09.txt AC 21 ms 384 KB
10.txt AC 15 ms 384 KB
11.txt AC 477 ms 20432 KB
12.txt TLE 2188 ms 1439888 KB
13.txt TLE 2175 ms 1211536 KB
14.txt TLE 2127 ms 400576 KB
15.txt AC 7 ms 256 KB
16.txt AC 14 ms 384 KB
17.txt AC 16 ms 384 KB
18.txt AC 41 ms 952 KB
19.txt TLE 2131 ms 472172 KB
20.txt TLE 2179 ms 1295672 KB
21.txt TLE 2179 ms 1303448 KB
22.txt TLE 2159 ms 926372 KB
23.txt AC 10 ms 256 KB
24.txt AC 22 ms 384 KB
25.txt AC 17 ms 384 KB
26.txt AC 45 ms 1496 KB
27.txt AC 1218 ms 43384 KB
28.txt TLE 2162 ms 971316 KB
29.txt TLE 2201 ms 1646052 KB
30.txt TLE 2141 ms 637564 KB
31.txt AC 10 ms 256 KB
32.txt AC 12 ms 384 KB
33.txt AC 11 ms 256 KB
34.txt AC 8 ms 256 KB
35.txt AC 604 ms 1048 KB
36.txt AC 647 ms 1024 KB
37.txt AC 176 ms 700 KB
38.txt AC 173 ms 672 KB
39.txt AC 2 ms 256 KB
40.txt AC 2 ms 256 KB
41.txt AC 6 ms 256 KB
42.txt AC 6 ms 256 KB
43.txt AC 8 ms 256 KB
44.txt AC 8 ms 256 KB
45.txt AC 6 ms 256 KB
46.txt AC 6 ms 256 KB
47.txt AC 7 ms 256 KB
48.txt AC 6 ms 256 KB
49.txt AC 1 ms 256 KB
50.txt AC 1 ms 256 KB
51.txt AC 1 ms 256 KB
52.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB