Submission #1208459

#TimeUsernameProblemLanguageResultExecution timeMemory
1208459mychecksedadArranging Tickets (JOI17_arranging_tickets)C++20
10 / 100
646 ms512 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' #define ff first #define ss second #define pii pair<int,int> #define vi vector<int> const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; struct Fenwick{ vector<int> t; Fenwick(int n){ t.resize(n + 1); } void add(int v, int x){ while(v < t.size()){ t[v]+=x; v += v & -v; } } int get(int v){ int res=0; while(v > 0){ res+=t[v]; v -= v&-v; } return res; } }; int n, m; array<int, 3> a[N]; void add(int l, int r, int x, Fenwick &fw){ for(int j = l; j < r; ++j) fw.add(j, x); } int get(int l, int r, Fenwick &fw){ int mx = 0; for(int j = l; j < r; ++j) mx= max(fw.get(j) - fw.get(j-1), mx); return mx; } void solve(){ cin >> n >> m; for(int i = 1; i <= m; ++i){ cin >> a[i][0] >> a[i][1] >> a[i][2]; if(a[i][1] < a[i][0]) swap(a[i][0], a[i][1]); } int ans = m; for(int i = 0 ; i < (1<<m); ++i){ Fenwick fw(25); for(int j = 0; j < m; ++j){ if((1<<j)&i){ add(a[j+1][0], a[j+1][1], 1, fw); }else{ add(1, a[j+1][0], 1, fw); add(a[j+1][1], n + 1, 1, fw); } } ans = min(ans, get(1, n+ 1, fw)); } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...