Advertisement
Guest User

swag 2016 must check it!

a guest
Oct 13th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 0.98 KB | None | 0 0
  1. #include <algorithm>
  2. #include <stdio.h>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <fstream>
  6. #include <tuple>
  7. #include <functional>
  8. #ifdef EVAL
  9. #define getc getc_unlocked
  10. #endif
  11.  
  12. using namespace std;
  13.  
  14. ofstream fout("output.txt");
  15.  
  16. //lista di adiacenza. vediamo se è faster
  17.  
  18.  
  19. FILE *fr;
  20.  
  21. int c, sol;
  22. int getInt(){
  23.     sol = 0;
  24.     while((c = getc(fr)) > 32)
  25.         sol = (sol<<3) + (sol<<1) + c - 48;
  26.     return sol;
  27. }
  28.  
  29. int main(){
  30.     fr = fopen("input.txt", "r");
  31.     int a, M = getInt(), F = getInt(), C = getInt();
  32.     vector<int> G[M];
  33.     for(int i = 0; i < C; i++){
  34.         a = getInt() - 1;
  35.         G[a].push_back(getInt());
  36.     }
  37.     vector<int> LIS;
  38.     for(vector<int> &m : G){
  39.         sort(m.begin(), m.end(), greater<int>());
  40.         for(int f : m){
  41.             auto ub = upper_bound(LIS.begin(), LIS.end(), f);
  42.             if(ub != m.begin() && *prev(ub) == f) //se non è strettamente minore
  43.                 continue;
  44.             else if(ub == LIS.end())
  45.                 LIS.push_back(f);
  46.             else
  47.                 *ub = f;
  48.         }
  49.     }
  50.     fout << LIS.size() * 2;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement