답안 #725265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725265 2023-04-17T05:51:25 Z Baytoro Pairs (IOI07_pairs) C++17
47 / 100
4000 ms 3412 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=1e5+5;
struct triple{
	int x,y,z;
};
void solve(){
	int b,n,d,m;
	cin>>b>>n>>d>>m;
	if(b==1){
		vector<int> a(n);
		for(int i=0;i<n;i++) cin>>a[i];
		sort(all(a));
		int ans=0;
		for(int i=0;i<n;i++){
			int j=upper_bound(all(a),a[i]+d)-a.begin();
			ans+=j-i-1;
		}
		cout<<ans<<endl;
	}
	else if(b==2){
		vector<pair<int,int>> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i].fr>>a[i].sc;
		}
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(abs(a[i].fr-a[j].fr)+abs(a[i].sc-a[j].sc)<=d) ans++;
			}
		}
		cout<<ans<<endl;
	}
	else{
		vector<triple> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i].x>>a[i].y>>a[i].z;
		}
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)+abs(a[i].z-a[j].z)<=d) ans++;
			}
		}
		cout<<ans<<endl;
	}
}
main(){
	//fopn("team");
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

pairs.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main(){
      | ^~~~
pairs.cpp: In function 'void fopn(std::string)':
pairs.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1480 KB Output is correct
2 Correct 14 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1880 KB Output is correct
2 Correct 19 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1876 KB Output is correct
2 Correct 21 ms 1864 KB Output is correct
3 Correct 19 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4038 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 2644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 3040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4070 ms 3180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4061 ms 3412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4070 ms 3412 KB Time limit exceeded
2 Halted 0 ms 0 KB -