結果

問題 No.497 入れ子の箱
ユーザー goodbatongoodbaton
提出日時 2017-06-05 22:29:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,564 ms / 5,000 ms
コード長 2,010 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 98,372 KB
実行使用メモリ 10,080 KB
最終ジャッジ日時 2023-10-22 05:40:47
合計ジャッジ時間 51,993 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,412 KB
testcase_01 AC 3 ms
5,412 KB
testcase_02 AC 2 ms
5,412 KB
testcase_03 AC 2,526 ms
10,080 KB
testcase_04 AC 2,539 ms
10,080 KB
testcase_05 AC 2,546 ms
10,080 KB
testcase_06 AC 2,549 ms
10,080 KB
testcase_07 AC 2,556 ms
10,080 KB
testcase_08 AC 2,549 ms
10,080 KB
testcase_09 AC 2,547 ms
10,080 KB
testcase_10 AC 2,563 ms
10,080 KB
testcase_11 AC 2,564 ms
10,080 KB
testcase_12 AC 1,307 ms
7,900 KB
testcase_13 AC 1,264 ms
7,820 KB
testcase_14 AC 1,250 ms
7,816 KB
testcase_15 AC 1,302 ms
7,892 KB
testcase_16 AC 1,312 ms
7,924 KB
testcase_17 AC 1,263 ms
7,820 KB
testcase_18 AC 2,558 ms
10,064 KB
testcase_19 AC 2,541 ms
10,068 KB
testcase_20 AC 2,528 ms
10,064 KB
testcase_21 AC 2,543 ms
10,064 KB
testcase_22 AC 2,544 ms
10,060 KB
testcase_23 AC 5 ms
5,468 KB
testcase_24 AC 5 ms
5,468 KB
testcase_25 AC 3 ms
5,412 KB
testcase_26 AC 3 ms
5,412 KB
testcase_27 AC 1,789 ms
8,768 KB
testcase_28 AC 1,797 ms
8,744 KB
testcase_29 AC 1,775 ms
8,688 KB
testcase_30 AC 7 ms
5,468 KB
testcase_31 AC 18 ms
5,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:81:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   81 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:86:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   86 |     scanf("%d%d%d",x[i]+0,x[i]+1,x[i]+2);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* TopologicalSort */

vector<int> TopologicalSort(vector<vector<int> > G,int n= -1){
  if(n==-1) n=(int)G.size();
  
  int u;
  vector<int> ret,ret2;
  queue<int> que;
  vector<int> indeg(n+1,0);
  
  for(int i=0;i<n;i++){
    for(int j=0;j<G[i].size();j++){
      indeg[G[i][j]]++;
    }
  }
  
  for(int i=0;i<n;i++){
    if(indeg[i]==0){
      que.push(i);
    }
  }
  
  while(!que.empty()){
    u = que.front();
    que.pop();
    
    ret.push_back(u);
    
    for(int i=0;i<G[u].size();i++){
      indeg[G[u][i]]--;
      if(indeg[G[u][i]]==0){
        que.push(G[u][i]);
      }
    }
  }
  
  if(n==(int)ret.size()){
    return ret;
  }else{
    return ret2;
  }
}



int main(){
  int n;
  int x[SIZE][3];

  
  scanf("%d",&n);

  vector<vector<int> > vec(n, vector<int>());

  for(int i=0;i<n;i++){
    scanf("%d%d%d",x[i]+0,x[i]+1,x[i]+2);

    sort(x[i],x[i]+3);
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i == j) continue;
      
      if(x[i][0] < x[j][0] &&
         x[i][1] < x[j][1] &&
         x[i][2] < x[j][2]){

        cerr << i << " -> " << j << endl;

        vec[i].push_back(j);
      }
    }
  }

  auto res = TopologicalSort(vec);
  
  int dp[SIZE] = {};
  int ans = 1;
  
  for(int i=0;i<res.size();i++){
    for(int j=0;j<vec[res[i]].size();j++){
      dp[vec[res[i]][j]] = max(dp[vec[res[i]][j]], dp[res[i]] + 1);
      ans = max(ans, dp[vec[res[i]][j]] + 1);
    }
  }

  printf("%d\n",ans);
  
  return 0;
}
0