Submission #1281893

#TimeUsernameProblemLanguageResultExecution timeMemory
1281893muhammad-mutahirAdvertisement 2 (JOI23_ho_t2)C++20
59 / 100
2103 ms338312 KiB
#include <bits/stdc++.h>
using namespace std;

#define print(l) for(auto i:l) cout<<i<<" ";cout<<endl;
#define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i];
#define int long long
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define all(l) l.begin(),l.end()
#define pii pair<int,int>
#define fi first
#define se second

const int M = 1e9+7;
const int inf = 1e18;
void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    // freopen("outputf.in","w",stdout);
    #endif
}

int bp(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0) {
 
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
int MI(int n, int p){
    return bp(n, p - 2, p);
}
int mul(int x,int y, int p){
    return x * 1ull * y % p;
}
int di(int x,int y, int p){
    return mul(x, MI(y, p), p);
}
map<int , vector<int>>adj;
map<int,int>give;
int n , m , k , q;

map<int,int>po;
map<int,int>inde;
map<int,int>outde;
map<int,int>mx;
map<int,int>mi;
void solve(int testcase_number){
    cin>>n;
    set<int>inp;
    for(int i = 0;i<n;i++){
    	cin>>m>>k;
    	inp.insert(m);
    	if(!mx[m]) mx[m] = -inf;
    	if(!mi[m]) mi[m] = inf;

    	mx[m] = max(mx[m],k);
    	mi[m] = mx[m];
    	// mi[m] = min(mi[m],k);
    	inde[m] = 0;
    }
    // n = inp.size();
    map<pair<int,int>,bool>ised;
    for(auto i:inp){
    	for(auto j:inp){
    		if(i < j and !ised[{i,j}]){
    			// if(i == 3 and j == 4){
    			// 	cout<<(i+mx[i] >= j+mi[j])<<" "<<i+mx[i]<<" "<<j+mi[j]<<endl;
    			// }
    			if(i+mx[i] >= j+mi[j]){
    				ised[{i,j}] = 1;
    				adj[i].pb(j);
    				inde[j]++;
    				outde[i]++;  		
    				// cout<<i<<" "<<j<<endl;

    			}
    		}
    		else if(i > j and !ised[{i,j}]){
    			if(i-mx[i] <= j-mi[j]){
    				ised[{i,j}] = 1;
    				// cout<<i<<" "<<j<<endl;
    				adj[i].pb(j);
    				inde[j]++;
    				outde[i]++;
    			}
    		}
    	}
    }

    // for(int i = 0;i<n;i++){
    // 	// print(i);
    // 	for(auto j:inp){
    // 		if(i == j)continue;
    // 		// print(i);
    // 		// print(j);
    // 		if(i[0] > j[0] and !ised[{i[0],j[1]}]){
    // 			if(i[2]<=j[2]){
    // 				ised[{i[0],j[1]}] = 1;
    // 				adj[i[0]].pb(j[0]);
    // 				inde[j[0]]++;
    // 				outde[i[0]]++;
    // 				// cout<<(i[2]>=j[2])<<i[2]<<" "<<j[2]<<" "<<i[0]<<" "<<j[0]<<endl;
    // 				// cout<<i[0]<<" "<<j[0]<<endl;
    // 			}
    // 		}
    // 		else if(i[0]<j[0] and !ised[{i[0],j[1]}]){
    // 			if(i[1]>=j[1]){
    // 				ised[{i[0],j[1]}] = 1;
    // 				adj[i[0]].pb(j[0]);
    // 				inde[j[0]]++;
    // 				outde[i[0]]++;
    // 				// cout<<i[1]<<" "<<j[1]<<" "<<i[0]<<" "<<j[0]<<endl;
    // 				// cout<<i[0]<<" "<<j[0]<<endl;
    // 			}
    // 		}
    // 	}
    // }
    int ans = 0;
    for(auto i:inde){
    	// cout<<i.fi<<" "<<i.se<<endl;
    	if(i.se == 0){
    		ans++;
    	}
    }
    cout<<ans+(ans == 0)<<endl;
    // for(auto i:adj){
    // 	// print(i.se);
    // 	for(int j:i.se){
    // 		cout<<i.fi<<" "<<j<<endl;
    // 	}
    // }
    // map<int,int>give;

    // }
    // for(auto i:inde){

    // }


    


}


signed main(){
    // io();

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);
    cout << fixed<<setprecision(9);

    int t = 1;
    // cin>>t;
    for(int i = 1;i<=t;i++){
        solve(i);
    }

}

Compilation message (stderr)

Main.cpp: In function 'void io()':
Main.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...