結果

問題 No.497 入れ子の箱
ユーザー goodbatongoodbaton
提出日時 2017-06-05 22:30:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,590 ms / 5,000 ms
コード長 2,008 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 98,432 KB
実行使用メモリ 8,516 KB
最終ジャッジ日時 2023-10-22 05:42:07
合計ジャッジ時間 52,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2,583 ms
8,516 KB
testcase_04 AC 2,574 ms
8,516 KB
testcase_05 AC 2,574 ms
8,516 KB
testcase_06 AC 2,586 ms
8,516 KB
testcase_07 AC 2,584 ms
8,516 KB
testcase_08 AC 2,590 ms
8,516 KB
testcase_09 AC 2,578 ms
8,516 KB
testcase_10 AC 2,576 ms
8,516 KB
testcase_11 AC 2,581 ms
8,516 KB
testcase_12 AC 1,322 ms
6,336 KB
testcase_13 AC 1,278 ms
6,256 KB
testcase_14 AC 1,251 ms
6,252 KB
testcase_15 AC 1,319 ms
6,328 KB
testcase_16 AC 1,322 ms
6,360 KB
testcase_17 AC 1,271 ms
6,256 KB
testcase_18 AC 2,584 ms
8,500 KB
testcase_19 AC 2,570 ms
8,504 KB
testcase_20 AC 2,559 ms
8,500 KB
testcase_21 AC 2,558 ms
8,500 KB
testcase_22 AC 2,574 ms
8,496 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 1,800 ms
7,204 KB
testcase_28 AC 1,799 ms
7,180 KB
testcase_29 AC 1,838 ms
7,124 KB
testcase_30 AC 6 ms
4,348 KB
testcase_31 AC 17 ms
4,348 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 1010

/* 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