Submission #26926578


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <utility>
#define rep(i,n) for (long long i=0;i<n;i++)

#define DENOM 998244353

using namespace std;
using ll = long long;

struct train_count{
  int l ;
  string s ;
  train_count(){
    this->l = 0 ;
    this->s = "" ;
  }
} ;

struct train{
  int id ;
  train *prev_train, *next_train ;
  train(int x){
    this->id = x ;
    this->prev_train = NULL ;
    this->next_train = NULL ;
  }
  train_count predecessor(){
    train_count result = train_count();
    train *train_predecessor = this->prev_train ;
    while (train_predecessor != NULL) {
      if (result.s == "") {
	result.s = to_string(train_predecessor->id) ;
      } else {
	result.s = to_string(train_predecessor->id) + " " + result.s ;
      }
      ++result.l ;
      train_predecessor = train_predecessor->prev_train ;
    }
    return(result) ;
  }
  train_count successor(){
    train_count result = train_count();
    train *train_successor = this->next_train ;
    while (train_successor != NULL) {
      if (result.s == "") {
	result.s = to_string(train_successor->id) ;
      } else {
	result.s = result.s + " " + to_string(train_successor->id) ;
      }
      ++result.l ;
      train_successor = train_successor->next_train ;
    }
    return(result) ;
  }
};




int main(){
  int n, q ;
  cin >> n >> q ;
  vector<train> v ;
  v.push_back(train(0)) ;
  rep(i, n) {
    v.push_back(train(i+1)) ;
  }
  rep(i, q) {
    int c, x, y ;
    cin >> c >> x;
    if (c!=3) {
      cin >> y ;
      if (c==1) {
	v[x].next_train = &v[y] ;
	v[y].prev_train = &v[x] ;
      }
      if (c==2) {
	v[x].next_train = NULL ;
	v[y].prev_train = NULL ;
      }
    } else {
      train_count pr = v[x].predecessor() ;
      train_count sr = v[x].successor() ;
      cout << pr.l + sr.l + 1 << " " << pr.s + " " + to_string(x) + " " + sr.s << endl ;
	
    }
  }
  return 0 ;
}

Submission Info

Submission Time
Task D - Play Train
User ntgo
Language C++ (Clang 10.0.0)
Score 0
Code Size 2104 Byte
Status TLE
Exec Time 2208 ms
Memory 9392 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 1
AC × 24
TLE × 1
Set Name Test Cases
Sample example0.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt
Case Name Status Exec Time Memory
000.txt AC 311 ms 9268 KiB
001.txt AC 600 ms 8980 KiB
002.txt AC 1089 ms 8972 KiB
003.txt AC 1997 ms 9364 KiB
004.txt TLE 2208 ms 6932 KiB
005.txt AC 570 ms 7452 KiB
006.txt AC 1110 ms 7548 KiB
007.txt AC 118 ms 3096 KiB
008.txt AC 118 ms 3076 KiB
009.txt AC 119 ms 3128 KiB
010.txt AC 118 ms 2992 KiB
011.txt AC 119 ms 3196 KiB
012.txt AC 117 ms 3020 KiB
013.txt AC 152 ms 3716 KiB
014.txt AC 157 ms 4272 KiB
015.txt AC 156 ms 4504 KiB
016.txt AC 157 ms 5856 KiB
017.txt AC 159 ms 5764 KiB
018.txt AC 162 ms 5948 KiB
019.txt AC 158 ms 5820 KiB
020.txt AC 160 ms 5916 KiB
021.txt AC 160 ms 5844 KiB
022.txt AC 321 ms 9368 KiB
023.txt AC 328 ms 9392 KiB
example0.txt AC 10 ms 3008 KiB