Skip to content

Commit 5dd80c1

Browse files
author
Jie Feng
committed
haha
1 parent ad4c6c4 commit 5dd80c1

File tree

13 files changed

+1926
-0
lines changed

13 files changed

+1926
-0
lines changed
878 KB
Binary file not shown.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// PROBLEM STATEMENT
2+
// Fox Ciel wants to hire a new maid.
3+
There are n candidates for the position.
4+
There are m different skills a maid should have, such as cooking, cleaning, or discreetness.
5+
Ciel numbered the candidates 0 through n-1 and the skills 0 through m-1.
6+
7+
8+
9+
Ciel evaluated the level each candidate has in each of the skills.
10+
You are given this information encoded in a vector <string> score with n elements, each consisting of m characters.
11+
For each i and j, the character score[i][j] represents the level candidate i has in skill j.
12+
Said character will always be between 'A' and 'Z', inclusive, where 'A' means the best possible and 'Z' the worst possible candidate.
13+
14+
15+
16+
Immediately after the reviews, the order of the candidates was {0, 1, ..., n-1}.
17+
Then, Ciel spent several days thinking about whom to hire.
18+
On each day, she chose one skill and reordered the candidates according to their level in that skill, from the best to the worst one.
19+
Whenever two candidates had the same level in the currently considered skill, she kept them in the order in which they were after the previous day.
20+
(Formally, the sorting algorithm she used was stable.)
21+
22+
23+
24+
You are given a vector <int> result containing a permutation of 0 through n-1.
25+
Return "Possible" (quotes for clarity) if it is possible that after zero or more days the order of candidates was precisely the one given in result.
26+
Otherwise, return "Impossible".
27+
28+
DEFINITION
29+
Class:CandidatesSelection
30+
Method:possible
31+
Parameters:vector <string>, vector <int>
32+
Returns:string
33+
Method signature:string possible(vector <string> score, vector <int> result)
34+
35+
36+
CONSTRAINTS
37+
-n will be between 1 and 50, inclusive.
38+
-m will be between 1 and 50, inclusive.
39+
-score will contain exactly n elements.
40+
-Each element of score will contain exactly m characters.
41+
-Each character in each element of score will be an uppercase English letter ('A'-'Z').
42+
-result will be a permutation of 0 through n-1.
43+
44+
45+
EXAMPLES
46+
47+
0)
48+
{"CC", "AA", "BB"}
49+
{1,2,0}
50+
51+
Returns: "Possible"
52+
53+
You can sort them by any skill to get the result.
54+
55+
1)
56+
{"BAB", "ABB", "AAB", "ABA"}
57+
{2,0,1,3}
58+
59+
Returns: "Possible"
60+
61+
We can first sort them by skill 0 to get {1, 2, 3, 0}, then sort them by skill 1 to get {2, 0, 1, 3}.
62+
63+
2)
64+
{"BAB", "ABB", "AAB", "ABA"}
65+
{0, 1, 3, 2}
66+
67+
Returns: "Impossible"
68+
69+
70+
71+
3)
72+
{"AAA", "ZZZ"}
73+
{1, 0}
74+
75+
Returns: "Impossible"
76+
77+
78+
79+
4)
80+
{"ZZZ", "AAA"}
81+
{0, 1}
82+
83+
Returns: "Possible"
84+
85+
Ciel can do no operation at all.
86+
87+
5)
88+
{"ZYYYYX","YXZYXY","ZZZZXX","XZXYYX","ZZZYYZ","ZZXXYZ","ZYZZXZ","XZYYZX"}
89+
{3,7,1,0,2,5,6,4}
90+
91+
Returns: "Possible"
92+
93+
94+
95+
#include <sstream>
96+
/*
97+
*/
98+
#define debuging
99+
#ifdef debuging
100+
#define FIN {freopen("new.in" , "r" , stdin) ;}
101+
#define FOUT {freopen("new.out" , "w" , stdout) ;}
102+
#define OUT(x) {cout<< #x << " : " << x <<endl ;}
103+
#define ERR(x) {cout<<"#error: "<< x ; while(1) ;}
104+
#endif
105+
// END CUT HERE
106+
#ifndef debuging
107+
#define FIN ;
108+
#define FOUT ;
109+
#define OUT(x) ;
110+
#define ERR(x) ;
111+
#endif
112+
#include <cstdio>
113+
#include <iostream>
114+
#include <cstring>
115+
#include <algorithm>
116+
#include <cmath>
117+
#include <vector>
118+
using namespace std ;
119+
#define bit(x,i) (x&(1<<i))
120+
#define max(a,b) (a<b?b:a)
121+
#define abs(x) (x<0?-x:x)
122+
#define IN(i,l,r) (l<i&&i<r)
123+
#define LINR(i,l,r) (l<=i&&i<=r)
124+
#define LIN(i,l,r) (l<=i&&i<r)
125+
#define INR(i,l,r) (l<i&&i<r)
126+
#define F(i,L,R) for (int i = L; i < R; i++)
127+
#define FE(i,L,R) for (int i = L; i <= R; i++)
128+
#define FF(i,L,R) for (int i = L; i > R; i--)
129+
#define FFE(i,L,R) for (int i = L; i >= R; i--)
130+
#define char2Int(c) (c-'0')
131+
#define lastEle(vec) vec[vec.size()-1]
132+
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n))
133+
#define clr(a,x) memset(a,x,sizeof(x))
134+
#define ll long long
135+
#define ui unsigned int
136+
#define us unsigned short
137+
const int maxint = -1u>>2 ;
138+
const double eps = 1e-6 ;
139+
class CandidatesSelection
140+
{
141+
public:
142+
string possible(vector <string> score, vector <int> result)
143+
{
144+
145+
146+
return string() ;
147+
}
148+
149+
150+
// BEGIN CUT HERE
151+
public:
152+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); }
153+
private:
154+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
155+
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
156+
void test_case_0() { string Arr0[] = {"CC", "AA", "BB"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1,2,0}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(0, Arg2, possible(Arg0, Arg1)); }
157+
void test_case_1() { string Arr0[] = {"BAB", "ABB", "AAB", "ABA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {2,0,1,3}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(1, Arg2, possible(Arg0, Arg1)); }
158+
void test_case_2() { string Arr0[] = {"BAB", "ABB", "AAB", "ABA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0, 1, 3, 2}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Impossible"; verify_case(2, Arg2, possible(Arg0, Arg1)); }
159+
void test_case_3() { string Arr0[] = {"AAA", "ZZZ"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 0}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Impossible"; verify_case(3, Arg2, possible(Arg0, Arg1)); }
160+
void test_case_4() { string Arr0[] = {"ZZZ", "AAA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0, 1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(4, Arg2, possible(Arg0, Arg1)); }
161+
void test_case_5() { string Arr0[] = {"ZYYYYX","YXZYXY","ZZZZXX","XZXYYX","ZZZYYZ","ZZXXYZ","ZYZZXZ","XZYYZX"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {3,7,1,0,2,5,6,4}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(5, Arg2, possible(Arg0, Arg1)); }
162+
163+
// END CUT HERE
164+
165+
};
166+
// BEGIN CUT HERE
167+
int main(){
168+
CandidatesSelection ___test;
169+
___test.run_test(-1);
170+
return 0;
171+
}
172+
// END CUT HERE
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include <cmath>
2+
#include <set>
3+
#include <list>
4+
#include <unordered_set>
5+
#include <hash_map>
6+
#include <climits>
7+
#include <queue>
8+
#include <vector>
9+
#include <map>
10+
#include <set>
11+
#include <cstdlib>
12+
#include <fstream>
13+
#include <iomanip>
14+
#include <iostream>
15+
#include <sstream> // istringstream buffer(myString);
16+
#include <stack>
17+
#include <algorithm>
18+
#include <cstring>
19+
#include <cassert>
20+
using namespace std;
21+
#define bit(x,i) (x&(1<<i))
22+
#define lowbit(x) ((x)&((x)^((x)-1)))
23+
#define pow2(x) (1<<x)
24+
//#define max(a,b) (a<b?b:a)
25+
//#define abs(x) (x<0?-x:x)
26+
#define IN(i,l,r) (l<i&&i<r)
27+
#define LINR(i,l,r) (l<=i&&i<=r)
28+
#define LIN(i,l,r) (l<=i&&i<r)
29+
#define INR(i,l,r) (l<i&&i<r)
30+
#define F(i,L,R) for (int i = L; i < R; i++)
31+
#define FE(i,L,R) for (int i = L; i <= R; i++)
32+
#define FF(i,L,R) for (int i = L; i > R; i--)
33+
#define FFE(i,L,R) for (int i = L; i >= R; i--)
34+
#define char2Int(c) (c-'0')
35+
#define lastEle(vec) vec[vec.size()-1]
36+
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n))
37+
#define clr(a,x) memset(a,x,sizeof(a))
38+
#define getI(a) scanf("%d", &a)
39+
#define getII(a,b) scanf("%d%d", &a, &b)
40+
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
41+
#define getS(x) scanf("%s", x);
42+
#define SZ(x) ((int)((x).size()))
43+
#define REMAX(a,b) (a)=max((a),(b));
44+
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
45+
#define REMIN(a,b) (a)=min((a),(b));
46+
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
47+
#define ALL(t) t.begin(),t.end()
48+
#define ll long long
49+
#define ull unsigned long long
50+
#define ui unsigned int
51+
#define us unsigned short
52+
#define IOS ios_base::sync_with_stdio(0);
53+
#define pb push_back
54+
#define INF 1001001001
55+
#define PI 3.1415926535897932384626
56+
#define mp make_pair
57+
#define ll long long
58+
#define fi first
59+
#define se second
60+
#define wez(n) int (n); scanf("%d",&(n));
61+
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
62+
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
63+
inline void pisz(int n) { printf("%d\n",n); }
64+
#define TESTS wez(testow)while(testow--)
65+
#define whileZ int T; getI(T); while(T--)
66+
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
67+
#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;}
68+
#define printV(a) printA(a,0,a.size()-1);
69+
#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;}
70+
#define MAXN 10000
71+
#define sz(a) int((a).size())
72+
#define pb push_back
73+
#define all(c) (c).begin(),(c).end()
74+
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
75+
#define present(c,x) ((c).find(x) != (c).end())
76+
#define cpresent(c,x) (find(all(c),x) != (c).end())
77+
78+
const int maxint = -1u>>2 ;
79+
const double eps = 1e-6 ;
80+
struct node{
81+
int p;
82+
char c;
83+
bool operator<(const node& other)const{
84+
if (c == other.c) return p < other.p;
85+
else return c < other.c;
86+
}
87+
};
88+
class CandidatesSelection
89+
{
90+
private:
91+
int n, m;
92+
bool calcPos(vector<int>& res, vector<node>& group, ull &pos){
93+
cout << "begiN____" << endl;
94+
sort(group.begin(), group.end());
95+
F(i,0,n) cout << group[i].c << ' ' ; cout << endl;
96+
F(i,0,n) cout << group[i].p << ' ' ; cout << endl;
97+
cout << "end_____" << endl << endl;
98+
99+
pos = 0;
100+
int i = 0;
101+
while(i < n){
102+
int j = i+1;
103+
while(j < n && group[j].c == group[i].c) j++;
104+
if (j - i == 1){
105+
if (group[i].p != res[i]) return false;
106+
else pos |= 1 << i;
107+
}
108+
i = j;
109+
}
110+
return true;
111+
}
112+
public:
113+
string possible(vector <string> score, vector <int> result)
114+
{
115+
printV(result);
116+
n = score.size();
117+
m = score[0].size();
118+
vector<node> group(n);
119+
vector<ull> pos;
120+
121+
F(i,0,m){
122+
F(j,0,n){
123+
group[j].p = j;
124+
group[j].c = score[j][i];
125+
}
126+
ull posb;
127+
if (calcPos(result, group, posb)){
128+
cout << posb << endl;
129+
printf("%llx\n", posb);
130+
pos.push_back(posb);
131+
}
132+
}
133+
ull res = 0;
134+
F(i,0,pos.size()) res |= pos[i];
135+
F(i,0,n) if ((res & (1 << n)) == 0) return "Impossible";
136+
137+
return "Possible";
138+
}
139+
// BEGIN CUT HERE
140+
public:
141+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); }
142+
private:
143+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
144+
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
145+
void test_case_0() { string Arr0[] = {"CC", "AA", "BB"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1,2,0}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(0, Arg2, possible(Arg0, Arg1)); }
146+
void test_case_1() { string Arr0[] = {"BAB", "ABB", "AAB", "ABA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {2,0,1,3}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(1, Arg2, possible(Arg0, Arg1)); }
147+
void test_case_2() { string Arr0[] = {"BAB", "ABB", "AAB", "ABA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0, 1, 3, 2}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Impossible"; verify_case(2, Arg2, possible(Arg0, Arg1)); }
148+
void test_case_3() { string Arr0[] = {"AAA", "ZZZ"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 0}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Impossible"; verify_case(3, Arg2, possible(Arg0, Arg1)); }
149+
void test_case_4() { string Arr0[] = {"ZZZ", "AAA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0, 1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(4, Arg2, possible(Arg0, Arg1)); }
150+
void test_case_5() { string Arr0[] = {"ZYYYYX","YXZYXY","ZZZZXX","XZXYYX","ZZZYYZ","ZZXXYZ","ZYZZXZ","XZYYZX"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {3,7,1,0,2,5,6,4}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); string Arg2 = "Possible"; verify_case(5, Arg2, possible(Arg0, Arg1)); }
151+
152+
// END CUT HERE
153+
154+
};
155+
// BEGIN CUT HERE
156+
int main(){
157+
CandidatesSelection ___test;
158+
___test.run_test(1);
159+
return 0;
160+
}
161+
// END CUT HERE

0 commit comments

Comments
 (0)