Projects >> DailyContest >>50db69f96fc5f089c79b9c631e66368a6f5383c9

Chunk
Conflicting content
		OutputStream outputStream = System.out;
		MyInputReader in = new MyInputReader(inputStream);
		MyOutputWriter out = new MyOutputWriter(outputStream);
<<<<<<< HEAD
		TaskE solver = new TaskE();
=======
		Security solver = new Security();
>>>>>>> ed13c4e842a20648bae0fdc9c44ac45513fae800
		solver.solve(1, in, out);
		out.close();
	}
Solution content
		OutputStream outputStream = System.out;
		MyInputReader in = new MyInputReader(inputStream);
		MyOutputWriter out = new MyOutputWriter(outputStream);

		Security solver = new Security();
		solver.solve(1, in, out);
		out.close();
	}
File
Main.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
		    boolean [][] table = new boolean[m][m];
	}
}

<<<<<<< HEAD
class TaskE {
	public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
        int n = in.nextInt(), q = in.nextInt();
        long[] values = new long[n];
        int[] colors = new int[n];
        for(int i = 0; i < n; i ++) values[i] = in.nextLong();
        for(int i = 0; i < n; i ++) colors[i] = in.nextInt();
        for(int k = 0; k < q; k ++) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.printLine(go(n, a, b, values, colors));
        }

=======
class Security {
    public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
	    int cases = in.nextInt();
	    for(int tc = 1; tc <= cases; tc ++) {
		    out.print("Case #" + tc + ": ");
		    int m = in.nextInt();
		    final char[] k1 = in.next().toCharArray();
		    final char[] k2 = in.next().toCharArray();
		    int n = k1.length;
		    assert (n % m == 0);
		    final int l = n / m;
		    final Integer[] order = new Integer[m];
		    for(int i = 0; i < m; i ++)
			    order[i] = i;
		    Arrays.sort(order, new Comparator() {
			    @Override
			    public int compare(Integer o1, Integer o2) {
				    int s1 = o1 * l;
				    int s2 = o2 * l;
				    for (int i = 0; i < l; i++)
					    if (k2[s1 + i] != k2[s2 + i]) {
						    return k2[s1 + i] - k2[s2 + i];
					    }
				    return 0;
			    }
		    });
		    for(boolean [] v : table) Arrays.fill(v, false);
		    for(int i = 0; i < m; i ++) {
		        for(int j = 0; j < m; j ++) {
			        table[i][j] = true;
			        for(int k = 0; k < l; k ++)
				        if(!Match(k1[i * l + k], k2[j * l + k])){
					        table[i][j] = false;
					        break;
				        }
		        }
		    }

		    int[] match = new int[m];
		    int ret = go(match, table, m);
		    if (ret != m){
			    out.printLine("IMPOSSIBLE");
		    } else {
			    for(int i = 0; i < m; i ++) {
				    int t = match[i];
				    int s = order[i];
				    for(int k = 0; k < l; k ++){
					    if(k1[t * l + k] == '?'){
						    if(k2[s * l + k] == '?')
							    k1[t * l + k] = 'a';
						    else
							    k1[t * l + k] = k2[s * l + k];
					    }
				    }
			    }
			    out.printLine(String.valueOf(k1));
		    }
	    }
    }

	private int go(int[] match, boolean[][] table, int n) {
		Arrays.fill(match, -1);
		boolean [] used = new boolean[n];
		int ret = 0;
		for(int i = 0; i < n; i ++){
			Arrays.fill(used, false);
			if(gao(i, n, match, table, used))
				ret ++;
		}
		return ret;
	}

	private boolean gao(int p, int n, int[] match, boolean[][] table, boolean[] used) {
		for(int i = 0; i < n; i ++) if(table[p][i] && !used[i]) {
			used[i] = true;
			if(match[i] == -1 || gao(match[i], n, match, table, used)){
				match[i] = p;
				return true;
			}
		}
		return false;
	}

	private boolean Match(char a, char c) {
		return a == c || a == '?' || c == '?';
>>>>>>> ed13c4e842a20648bae0fdc9c44ac45513fae800
	}

    private long go(int n, int a, int b, long[] values, int[] colors) {
Solution content
	}
}
class Security {
    public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
	    int cases = in.nextInt();
	    for(int tc = 1; tc <= cases; tc ++) {
		    out.print("Case #" + tc + ": ");
		    int m = in.nextInt();
		    final char[] k1 = in.next().toCharArray();
		    final char[] k2 = in.next().toCharArray();
		    int n = k1.length;
		    assert (n % m == 0);
		    final int l = n / m;
		    final Integer[] order = new Integer[m];
		    for(int i = 0; i < m; i ++)
			    order[i] = i;
		    Arrays.sort(order, new Comparator() {
			    @Override
			    public int compare(Integer o1, Integer o2) {
				    int s1 = o1 * l;
				    int s2 = o2 * l;
				    for (int i = 0; i < l; i++)
					    if (k2[s1 + i] != k2[s2 + i]) {
						    return k2[s1 + i] - k2[s2 + i];
					    }
				    return 0;
			    }
		    });
		    boolean [][] table = new boolean[m][m];
		    for(boolean [] v : table) Arrays.fill(v, false);
		    for(int i = 0; i < m; i ++) {
		        for(int j = 0; j < m; j ++) {
			        table[i][j] = true;
			        for(int k = 0; k < l; k ++)
				        if(!Match(k1[i * l + k], k2[j * l + k])){
					        table[i][j] = false;
					        break;
				        }
		        }
		    }

		    int[] match = new int[m];
		    int ret = go(match, table, m);
		    if (ret != m){
			    out.printLine("IMPOSSIBLE");
		    } else {
			    for(int i = 0; i < m; i ++) {
				    int t = match[i];
				    int s = order[i];
				    for(int k = 0; k < l; k ++){
					    if(k1[t * l + k] == '?'){
						    if(k2[s * l + k] == '?')
							    k1[t * l + k] = 'a';
						    else
							    k1[t * l + k] = k2[s * l + k];
					    }
				    }
			    }
			    out.printLine(String.valueOf(k1));
		    }
	    }
    }

	private int go(int[] match, boolean[][] table, int n) {
		Arrays.fill(match, -1);
		boolean [] used = new boolean[n];
		int ret = 0;
		for(int i = 0; i < n; i ++){
			Arrays.fill(used, false);
			if(gao(i, n, match, table, used))
				ret ++;
		}
		return ret;
	}

	private boolean gao(int p, int n, int[] match, boolean[][] table, boolean[] used) {
		for(int i = 0; i < n; i ++) if(table[p][i] && !used[i]) {
			used[i] = true;
			if(match[i] == -1 || gao(match[i], n, match, table, used)){
				match[i] = p;
				return true;
			}
		}
		return false;
	}

	private boolean Match(char a, char c) {
		return a == c || a == '?' || c == '?';
	}

    private long go(int n, int a, int b, long[] values, int[] colors) {
File
Main.java
Developer's decision
Version 2
Kind of conflict
Class signature
For statement
Method declaration
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
        return readInt() ;
    }

<<<<<<< HEAD
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public long nextLong(){
        return readLong();
=======
    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
>>>>>>> ed13c4e842a20648bae0fdc9c44ac45513fae800
    }

    public static boolean isSpaceChar(int c) {
Solution content
        return readInt() ;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public static boolean isSpaceChar(int c) {
File
Main.java
Developer's decision
Version 2
Kind of conflict
Do statement
Method declaration
Method invocation
Method signature
Return statement
Variable
While statement