Showing posts with label croc champ. Show all posts
Showing posts with label croc champ. Show all posts

Tuesday, May 28, 2013

Croc Champ 2013 - Round 2 (Div. 2 Edition) C Weird Game

// Croc Champ 2013 - Round 2 (Div. 2 Edition) C Weird Game

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;
    private static boolean LOCAL_TEST = false;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        char[] s = in.nextString().toCharArray();
        char[] t = in.nextString().toCharArray();
        int n10 = 0;
        int n11 = 0;
        int n01 = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == '1' && t[i] == '0')
                n10++;
            else if (s[i] == '1' && t[i] == '1')
                n11++;
            else if (s[i] == '0' && t[i] == '1')
                n01++;
        }
        int ns = 0;
        if (n11 % 2 == 1)
            ns += 1;
        ns += n10 - n01;
        if (ns > 0)
            out.println("First");
        else if (ns >= -1)
            out.println("Draw");
        else
            out.println("Second");
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        out = System.out;
        try {
            String cname = System.getenv("COMPUTERNAME");
            LOCAL_TEST = (cname.equals("ALPHA530"));
        } catch (Exception e) {
        }
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}

Croc Champ 2013 - Round 2 (Div. 2 Edition) B Ksusha the Squirrel

// Croc Champ 2013 - Round 2 (Div. 2 Edition) B Ksusha the Squirrel

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;
    private static boolean LOCAL_TEST = false;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        int K = in.nextInt();
        char[] c = in.nextString().toCharArray();
        int maxAdjacentRocks = 0;
        int nRock = 0;
        if (c[0] == '#')
            nRock = 1;
        for (int i = 1; i < c.length; i++) {
            if (c[i - 1] == '#')
                nRock++;
            else
                nRock = 0;
            maxAdjacentRocks = Math.max(maxAdjacentRocks, nRock);
        }
        if (maxAdjacentRocks < K)
            out.println("YES");
        else
            out.println("NO");
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        out = System.out;
        try {
            String cname = System.getenv("COMPUTERNAME");
            LOCAL_TEST = (cname.equals("ALPHA530"));
        } catch (Exception e) {
        }
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}

Croc Champ 2013 - Round 2 (Div. 2 Edition) A Ksusha and Array

//Croc Champ 2013 - Round 2 (Div. 2 Edition) A Ksusha and Array
import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;
    private static boolean LOCAL_TEST = false;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int num = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] % num != 0) {
                num = -1;
                break;
            }
        }
        out.println(num);
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        out = System.out;
        try {
            String cname = System.getenv("COMPUTERNAME");
            LOCAL_TEST = (cname.equals("ALPHA530"));
        } catch (Exception e) {
        }
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}

Friday, May 10, 2013

Croc Champ 2013 - Round 1 B Network Topology

// Croc Champ 2013 - Round 1 B Network Topology

import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.*;
import java.text.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;
    // change to false before submitting
    private static boolean LOCAL_TEST = false;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        int M = in.nextInt();
        int[] nodeNumConnected = new int[N + 1];
        for (int i = 1; i < nodeNumConnected.length; i++) {
            nodeNumConnected[i] = 0;
        }
        for (int i = 0; i < M; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            nodeNumConnected[x] += 1;
            nodeNumConnected[y] += 1;
        }
        boolean isRing = true;
        boolean isBus = true;
        int maxCon = 0;
        int numCon1 = 0;
        int numConNot1 = 0;
        for (int i = 1; i < nodeNumConnected.length; i++) {
            maxCon = Math.max(maxCon, nodeNumConnected[i]);
            if (nodeNumConnected[i] == 1)
                numCon1++;
            else
                numConNot1++;
            if (nodeNumConnected[i] != 2)
                isRing = false;
            if (nodeNumConnected[i] > 2)
                isBus = false;
        }
        if (isBus && numCon1 == 2)
            out.print("bus topology");
        else if (isRing)
            out.print("ring topology");
        else if (numCon1 == N - 1 && numConNot1 == 1 && maxCon == (N - 1))
            out.print("star topology");
        else
            out.print("unknown topology");
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        out = System.out;
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}

Croc Champ 2013 - Round 1 A SMSC

// Croc Champ 2013 - Round 1 A SMSC

import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.*;
import java.text.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;
    // change to false before submitting
    private static boolean LOCAL_TEST = false;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        int[] t = new int[N];
        int[] c = new int[N];
        for (int i = 0; i < N; i++) {
            t[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        long lasttime = 0;
        long qlen;
        long curt;
        curt = t[0];
        qlen = c[0];
        long maxq = qlen;
        for (int i = 1; i < N; i++) {
            if (qlen > 0) {
                qlen--;
            }
            if (t[i] - curt - 1 <= qlen)
                qlen = qlen - (t[i] - curt - 1);
            else
                qlen = 0;
            qlen = qlen + c[i];
            maxq = Math.max(maxq, qlen);
            curt = t[i];
        }
        lasttime = curt + qlen;
        out.print(lasttime);
        out.print(" ");
        out.println(maxq);
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        out = System.out;
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}

Tuesday, May 7, 2013

Croc Champ 2013 - Qualification Round A Spyke Talks

// Croc Champ 2013 - Qualification Round A Spyke Talks

import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.*;
import java.text.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
    private static MyScanner in;
    private static PrintStream out;

    private static void solve() throws IOException
    {
        int N = in.nextInt();
        long[] id = new long[N];
        for (int i = 0; i < N; i++) {
            id[i] = in.nextLong();
        }
        Arrays.sort(id);
        int npairs = 0;
        int cnt = 1;
        boolean mistake = false;
        for (int i = 1; i < id.length; i++) {
            if (id[i] == 0)
                continue;
            if (id[i] == id[i - 1])
                cnt++;
            else
                cnt = 1;
            if (cnt > 2) {
                mistake = true;
                break;
            }
            else if (cnt == 2) {
                npairs++;
            }
        }
        if (mistake)
            out.print(-1);
        else
            out.print(npairs);
    }

    public static void main(String[] args) throws IOException {
        // helpers for input/output
        boolean LOCAL_TEST = false;// change to false before submitting
        out = System.out;
        if (LOCAL_TEST) {
            in = new MyScanner("E:\\zin.txt");
        }
        else {
            boolean usingFileForIO = false;
            if (usingFileForIO) {
                // using input.txt and output.txt as I/O
                in = new MyScanner("input.txt");
                out = new PrintStream("output.txt");
            }
            else {
                in = new MyScanner();
                out = System.out;
            }
        }

        solve();
    }

    // =====================================
    static class MyScanner {
        Scanner inp = null;

        public MyScanner() throws IOException
        {
            inp = new Scanner(System.in);
        }

        public MyScanner(String inputFile) throws IOException {
            inp = new Scanner(new FileInputStream(inputFile));
        }

        public int nextInt() throws IOException {
            return inp.nextInt();
        }

        public long nextLong() throws IOException {
            return inp.nextLong();
        }

        public double nextDouble() throws IOException {
            return inp.nextDouble();
        }

        public String nextString() throws IOException {
            return inp.next();
        }

    }

}