답안 #382076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382076 2021-03-26T11:11:48 Z nikolapesic2802 Flood (IOI07_flood) C++14
73 / 100
226 ms 65540 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define D(x) cerr << #x << " is " << (x) << "\n";
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> istream& operator>>(istream& is,pair<T1,T2>& a) {is>>a.f>>a.s;return is;}
template<class T> istream& operator>>(istream& is,vector<T>& a) {for(auto &p:a)is>>p;return is;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

//0 Gore, 1 Desno, 2 Dole, 3 Levo
const int N=1e5+5;
int nxt[4][N],ind[4][N],cnt[N],start;
vector<int> del,sol;
bool dfs(int tr,int d){
	//printf("%i %i\n",tr,d);
	if(start==tr&&d!=4)
		return true;
	for(int s=d+3;s<d+7;s++){
		int i=s%4;
		if(ind[i][tr]!=0&&cnt[ind[i][tr]]!=-1){
			cnt[ind[i][tr]]++;
			if(cnt[ind[i][tr]]==1)
				del.pb(ind[i][tr]);
			if(dfs(nxt[i][tr],i))
				return true;
		}
	}
	return false;
}
void finish(){
	while(del.size()){
		//printf("Del %i\n",del.back());
		//assert(cnt[del.back()]==1||cnt[del.back()]==2);
		if(cnt[del.back()]==2)
			sol.pb(del.back());
		cnt[del.back()]=-1;
		del.pop_back();
	}
}
int main()
{
	int n;
	cin>>n;
	vector<pair<pair<int,int>,int>> p;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		p.pb({{x,y},i});
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		int c;
		if(p[u].f.f==p[v].f.f)
			c=p[u].f.s<p[v].f.s?0:2;
		else
			c=p[u].f.f<p[v].f.f?1:3;
		nxt[c][u]=v;
		nxt[c^2][v]=u;
		ind[c][u]=i+1;
		ind[c^2][v]=i+1;
	}
	sort(all(p));
	for(int i=0;i<n;i++)
		start=p[i].s,dfs(p[i].s,4),finish(),dfs(p[i].s,4),finish();
	cout<<sol.size()<<endl;
	sort(all(sol));
	for(auto p:sol)
		cout<<p<<endl;
	return 0;
}

Compilation message

flood.cpp: In function 'int ri()':
flood.cpp:36:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 | int ri(){int x;scanf("%i",&x);return x;}
      |                ~~~~~^~~~~~~~~
flood.cpp: In function 'void rd(int&)':
flood.cpp:37:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 | void rd(int&x){scanf("%i",&x);}
      |                ~~~~~^~~~~~~~~
flood.cpp: In function 'void rd(long long int&)':
flood.cpp:38:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 | void rd(long long&x){scanf("%lld",&x);}
      |                      ~~~~~^~~~~~~~~~~
flood.cpp: In function 'void rd(double&)':
flood.cpp:39:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 | void rd(double&x){scanf("%lf",&x);}
      |                   ~~~~~^~~~~~~~~~
flood.cpp: In function 'void rd(long double&)':
flood.cpp:40:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 | void rd(long double&x){scanf("%Lf",&x);}
      |                        ~~~~~^~~~~~~~~~
flood.cpp: In function 'void rd(char*)':
flood.cpp:42:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 | void rd(char*x){scanf("%s",x);}
      |                 ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 7904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 4704 KB Output is correct
2 Runtime error 226 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 214 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 217 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -