Enumerates T plus two to determine if the current T is feasible and to find S.
Be careful not to say |a[n]| <= |3-a[n]| proves that there is no solution, the beginning is WA here.
You can simply imagine that every time a[n] win, both people play the Hollingsworth (win only one round), and whenever A[n] lose, the round did not win.
Under this premise, there is clearly a |a[n]| <= |3-a[n]|.
1 /*283D*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A the Const intMAXN = 1e5+5; + intA[MAXN]; - intcnt[3][MAXN]; $ intN; $ intID; - - intCalcintt) { the intI, J, p, Q; - intc[3];Wuyi intb[3]; the -b[1] = b[2] =0; Wuc[1] = c[2] =0; -p =0; About while(1) { $i = Lower_bound (cnt[1]+p, cnt[1]+1+n, c[1]+t)-(cnt[1]); -j = Lower_bound (cnt[2]+p, cnt[2]+1+n, c[2]+t)-(cnt[2]); - if(cnt[1][i]-c[1]!=t && cnt[2][j]-c[2]!=t) - return 0; A if(I <j) { + //1 win theQ =1; -++b[1]; $p =i; the}Else { theQ =2; the++b[2]; thep =J; - } inc[1] = cnt[1][p]; thec[2] = cnt[2][p]; the if(P >=N) About Break; the } the the if(P! =N) + return 0; - the intId_ =3-ID;Bayi if(B[id_]>=b[id] | | q!=ID) the return 0; the returnB[id]; - } - the intMain () { theIos::sync_with_stdio (false); the #ifndef Online_judge theFreopen ("data.in","R", stdin); -Freopen ("Data.out","W", stdout); the #endif the the intc[3];94 thescanf"%d", &n); thec[1] = c[2] =0; theRep (I,1, n+1) {98scanf"%d", &a[i]); About++C[a[i]]; -Cnt[a[i]][i] = cnt[a[i]][i-1] +1;101cnt[3-a[i]][i] = cnt[3-a[i]][i-1];102 }103cnt[1][n+1] = cnt[2][n+1] =Int_max;104 theID =A[n];106 intan = C[id], bn = c[1]+c[2]-an ;107 108 //if (an <= bn) {109 //puts ("0"); the //return 0;111 // } the 113 intI, J; the vpii ans; the the for(i=1; i<=n; ++i) {117j =Calc (i);118 if(j)119 ANS.PB (MP (J, I)); - }121 122 sort (All (ans));123 124n =SZ (ans); theprintf"%d\n", n);126Rep (I,0, N) {127printf"%d%d\n", Ans[i].fir, ans[i].sec); - }129 the #ifndef Online_judge131printf"Time =%d.\n", (int) clock ()); the #endif133 134 return 0;135}
"CF" 283D tennis Game