Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AmanRaj1608/6cdda924ea6f73f88df43ed6cd3cbfc8 to your computer and use it in GitHub Desktop.
Save AmanRaj1608/6cdda924ea6f73f88df43ed6cd3cbfc8 to your computer and use it in GitHub Desktop.
code jam Qualification Round 2020 my codes
// AmanRaj1608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<ll>
#define pb push_back
#define rep(i,a,b) for(ll i = a; i<b; ++i)
#define f(a) for(ll i = 0; i<a; ++i)
#define p(a) cout << a << "\n";
#define p2(a,b) cout << a << " " << b << "\n";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
void ques1() {
ll n; cin>>n;
ll v[n][n];
rep(i,0,n) rep(j,0,n) cin>>v[i][j];
vi store(n+1,0);
ll row{0}, column{0}, ans{0};
rep(i,0,n) {
rep(_,0,n+1) store[_]=0;
rep(j,0,n) {
if(store[v[i][j]]==0)
store[v[i][j]] = 1;
else {
row++;
break;
}
}
}
rep(i,0,n) {
rep(_,0,n+1) store[_]=0;
rep(j,0,n) {
if(store[v[j][i]]==0)
store[v[j][i]] = 1;
else {
column++;
break;
}
}
}
// Add diagnol
rep(i,0,n) ans += v[i][i];
cout << ans << ' ' << row << ' ' << column << '\n';
}
void ques2() {
string s, ans = "";;
cin >> s;
ll n = s.size(), rem=0, num;
rep(i,0,n) {
ll var = s[i]-'0';
if(rem-var>0) {
num = rem - var;
rem = rem-num;
rep(j,0,num) ans += ')';
}
else if(rem-var<0) {
num = var-rem;
rem += num;
rep(j,0,num) ans += '(';
}
ans+=s[i];
}
while(rem--) ans += ')';
p(ans)
}
void ques3() {
ll n; cin>>n;
string ans="";
vector< pair<ll,ll>> v(n);
vi ind(n,0);
rep(i,0,n) ind[i] = i;
f(n) cin>>v[i].first>>v[i].second;
// Sort with v
sort(ind.begin(), ind.end(), [&](ll i, ll j) {
return (v[i] < v[j]);
});
ll c=0,j=0,f=0;
f(n) ans+='1';
f(n) {
if(c <= v[ind[i]].first) {
ans[ind[i]] = 'C';
c = v[ind[i]].second;
}
else {
if(v[ind[i]].first < j) {
ans = "IMPOSSIBLE";
break;
}
else {
j = v[ind[i]].second;
ans[ind[i]] = 'J';
}
}
}
cout << ans << '\n';
}
void ques4() {
//
}
void ques5() {
ll n,k;
cin>>n>>k;
if(k%n==0 && k<=n*n) {
ll a[n][n], ar[n];
ar[0] = k/n;
ar[(k/n)-1]=1;
rep(i,0,n) {
if(i==0 || i+1==k/n) continue;
ar[i]=i+1;
}
rep(i,0,n) {
for (ll j=0,l=0;j<n;j++,l++) {
a[i][j]=ar[l];
}
int temp=ar[n-1];
for (int i=n-1;i>=0;i--) {
ar[i]=ar[i-1];
}
ar[0]=temp;
}
p("POSSIBLE")
rep(i,0,n) {
for (ll j=0,l=0;j<n;j++) {
cout<<a[i][j]<<" ";
}
p("")
}
}
else {
p("IMPOSSIBLE")
}
}
int32_t main() {
fast_io;
ll tt; cin >> tt;
f(tt) {
cout<<"Case #"<<i+1 <<": ";
// ques1();
// ques2();
ques3();
// ques4();
// ques5();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment