Submission #556222

# Submission time Handle Problem Language Result Execution time Memory
556222 2022-05-02T15:29:57 Z 600Mihnea Team Contest (JOI22_team) C++17
0 / 100
2000 ms 5068 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

struct T {
  int x;
  int y;
  int z;
  int tx;
  int ty;
  int tz;
};

bool cmp_x_inv(T a,T b) {
  return a.x>b.x;
}

typedef long long ll;
const int N=150000+7;
const int INF=(int)1e9+7;
int n,zm[N],invz[N],value[N];
T a[N];
int aib1[N];

void clr1() {
  for (int i=1;i<=n;i++) aib1[i]=-INF;
}

int get1(int i) {
  int sol=-INF;
  while (i) {
    sol=max(sol,aib1[i]);
    i-=i&(-i);
  }
  return sol;
}

void upd1(int i,int x) {
  while (i<=n){
    aib1[i]=max(aib1[i],x);
    i+=i&(-i);
  }
}

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  cin>>n;
  for (int i=1;i<=n;i++) {
    cin>>a[i].x>>a[i].y>>a[i].z;
  }
  sort(a+1,a+n+1,cmp_x_inv);
  {
    map<int, int> tx,ty,tz;
    for (int i=1;i<=n;i++) tx[a[i].x]=0,ty[a[i].y]=0,tz[a[i].z]=0;
    int ind;
    ind=0; for (auto &it:tx)it.second=++ind;
    ind=0; for (auto &it:ty)it.second=++ind;
    ind=0; for (auto &it:tz)it.second=++ind, invz[ind]=it.first;
    for (int i=1;i<=n;i++) a[i].tx=tx[a[i].x], a[i].ty=ty[a[i].y], a[i].tz=tz[a[i].z];
  }
  int print=-1;

  for (int ITER=0;ITER<2;ITER++) {
    clr1();

    for (int i=n;i>=1;i--) { /// optimize using aib
      zm[i]=get1(a[i].ty-1);
      upd1(a[i].ty,a[i].tz);
      if (zm[i]<=a[i].z) zm[i]=-INF;
      if(zm[i]!=-INF) zm[i]=invz[zm[i]];
    }

    int last=n;
    while(last>=1){
      int first=last;
      while(first-1>=1&&a[first-1].x==a[first].x) first--;

      for (int i=first;i<=last;i++) {
        int best=-INF;
        int y=a[i].y,z=a[i].z;

        for (int j=last+1;j<=n;j++) {
          if (a[j].y>y&&zm[j]>z) {
            best=max(best,zm[j]+a[j].y);
          }
        }
        print=max(print,best+a[i].x);
      }

      last=first-1;
    }
    for (int i=1;i<=n;i++) swap(a[i].y,a[i].z), swap(a[i].ty,a[i].tz);
  }

  cout<<print<<"\n";
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2077 ms 5068 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2077 ms 5068 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2077 ms 5068 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2077 ms 5068 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -