Code Knights Round 10 Results and Problem Analysis ?>

Code Knights Round 10 Results and Problem Analysis

Problem A’s Solution by Amjad:

#include <iostream>
using namespace std;
int n ;
int tmp;
int tallest = 1 ; 
int shortest = (1<<31)-1;
int main(){
    cin >> n ; 
    for(int i=0;i<n;i++){
        cin >> tmp;
        if ( tmp > tallest ) tallest = tmp;
        if ( tmp < shortest ) shortest = tmp;
    }
    cout << tallest << " " << shortest << endl;
    return 0;
}

Problem B’s Solution by Amjad:

#include <iostream>
#include <algorithm>
using namespace std;
int n ;
int a[1000001];
int main(){
    cin >> n ; 
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    cout << a[0];
    for(int i=1;i<n;i++){
        cout << " " << a[i];
    }
    cout << endl;
    return 0;
}

Problem C’s Solution by Asyraf:

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pii;
#define REP(i,n) for(ll i=0;i<n;i++)

#ifdef DEBUG
#define dbg(x) x
#define dbgp(x) cerr << x << endl;
#else
#define dbg(x) //x
#define dbgp(x) //cerr << x << endl;
#endif

int main(){
    int n;
    cin >> n;
    set<int> graph[n];

    REP(i, n){
        int c;
        cin >> c;
        REP(j, c){
            int d;
            cin >> d;
            d--;
            graph[i].insert(d);
        }
    }

    int k;
    cin >> k;
    vector<int> instructions;
    REP(i, k){
        int d;
        cin >> d;
        d--;
        instructions.push_back(d);
    }

    bool valid = true;
    int cur = instructions[0];
    for(int i=1;i<instructions.size();i++){
        int next = instructions[i];
        if(graph[cur].find(next) == graph[cur].end() && next != cur){
            valid = false;
            break;
        }
        cur = next;
    }

    if(valid){
        cout << "Instruction is OK" << endl;
    }else{
        cout << "This instruction will lead you astray" << endl;
    }

}

Problem D’s Solution by Zarir:

#include <iostream>

using namespace std;

#define ll long long
#define MX 20

ll fact[MX+1];

int main(){
	fact[0]=1;
	for(int i=1;i<=MX;i++) fact[i] = fact[i-1]*i;
	int k,n,q;
	cin>>k>>n>>q;
	int pk;
	ll co;
	while(q--){
		co = fact[n];
		for(int i=0;i<k;i++){
			cin>>pk;
			co /= fact[pk];
		}
		cout<<co<<endl;
	}
	return 0;
}

Problem E’s Solution by Ayesha:

#include <bits/stdc++.h>
using namespace std;

int main(){
	int t, n = 12, input;
	int de[100], f[100];
	de[0] = 1;
	f[0] = 1;
	de[1] = 0;
	f[1] = 1;
	for(int i=2 ; i<=n; i++){
		de[i] = (i-1) * (de[i-1]+de[i-2]);
		f[i] = f[i-1]*i;
	}
	cin >> t;
	while(t--){
		cin >> input;
		cout << de[input] << "/" << f[input] << endl;
	}
	return 0;
}