Harigami
ログイン
123
anonymous タイトルなし
C++
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)

typedef long long ll;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;

int T[123][123] = {};
ll Cost[123][123] =  {};
int H,W,C;

bool IsIn(int x,int y){
    return 0<=x&&x<H&&0<=y&&y<W;
}
int main() {
    cin>>H>>W>>C;
    rep(i,H)rep(j,W){
        cin>>T[i][j];
        Cost[i][j] = INF;
    }
    Cost[0][0] = 0;
    queue<pair<int,int>> Q;
    Q.push({0,0});
    while(!Q.empty()){
        auto p =  Q.front();
        int x = p.first;
        int y = p.second;
        Q.pop();
        rep(i,2){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!IsIn(nx,ny))continue;
            if(T[nx][ny]==1){
                //chmin(Cost[nx][ny], Cost[x][y] + C);
                Cost[nx][ny] = min(Cost[nx][ny], Cost[x][y] + C);
            }
            else{
                Cost[nx][ny] = min(Cost[nx][ny], Cost[x][y]);
                //chmin(Cost[nx][ny], Cost[x][y]);
            }
            Q.push({nx,ny});
        }
    }
    cout<<Cost[H-1][W-1]<<endl;
}
  • 0
  • 1
Retired K@PCK タイトルなし
C++
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================
  • 0
  • 1
monkukui タイトルなし
C++
50 149
45 47 8
36 44 2
27 34 10
47 9 9
9 45 1
4 9 5
29 24 4
28 3 6
10 7 1
9 33 2
29 25 1
35 20 1
47 4 10
49 24 5
16 35 1
39 23 9
7 26 1
45 33 1
19 43 8
11 25 4
17 26 1
23 18 8
28 18 9
24 31 1
40 1 6
17 20 9
42 5 10
39 28 4
10 40 5
9 22 2
4 33 1
17 7 1
6 27 1
24 49 5
40 2 6
48 28 6
4 33 1
23 28 1
37 25 5
12 23 9
5 44 6
45 22 3
18 48 1
16 20 1
19 1 8
39 14 10
37 49 8
33 47 7
24 25 2
39 32 2
43 1 1
36 8 1
44 8 7
37 39 2
23 3 6
44 36 2
6 27 1
32 3 2
32 14 6
11 30 6
14 32 6
22 9 2
25 31 1
9 15 10
48 30 5
29 38 9
11 31 9
4 22 8
17 26 1
38 39 1
47 22 2
21 14 6
1 40 6
38 23 8
12 7 8
1 43 1
30 18 7
1 19 8
36 6 9
44 46 3
31 25 1
38 11 9
47 22 2
48 23 6
37 14 6
48 18 1
48 30 5
17 10 3
13 42 3
48 28 6
46 4 8
32 38 4
4 44 4
10 40 5
25 38 6
8 27 6
23 32 10
28 38 2
16 50 9
1 2 5
39 25 7
19 35 8
7 17 1
36 8 1
44 46 3
4 44 4
8 18 10
29 11 2
18 27 9
18 27 9
29 37 10
3 38 9
35 19 8
33 44 8
38 28 2
37 31 6
26 12 4
17 35 10
46 5 1
28 32 6
31 49 8
45 9 1
4 36 6
4 8 10
24 31 1
38 39 1
26 10 6
41 21 10
39 32 2
46 5 1
39 37 2
3 12 6
26 12 4
8 6 6
11 29 2
31 29 2
37 24 7
50 16 9
23 28 1
22 33 4
35 20 1
32 37 4
39 3 7
33 45 1
3 32 2
40 19 9
25 37 5
45 4 2
37 38 4
  • 0
  • 0
monkukui タイトルなし
C++
50 100
47 3 6
42 36 9
45 19 10
46 15 5
13 41 2
7 49 9
8 14 9
3 42 3
11 12 5
15 30 2
24 11 4
33 46 10
8 43 7
12 35 4
22 27 10
10 18 2
11 39 6
45 16 1
32 48 4
39 16 6
25 44 7
48 28 4
29 49 3
15 12 5
1 31 3
37 24 8
27 9 2
15 27 6
16 15 9
15 35 5
7 17 8
11 19 4
10 32 10
28 38 8
32 3 4
33 9 8
5 23 7
48 39 7
30 6 5
23 18 7
46 9 2
38 49 8
41 27 9
22 38 3
47 2 4
23 21 6
16 43 8
32 23 2
39 28 10
33 40 4
2 17 2
13 26 3
25 13 10
4 16 1
3 20 4
41 40 3
40 10 10
37 3 10
20 34 3
33 17 7
24 20 6
32 14 9
37 31 10
14 33 5
49 16 7
31 34 8
38 18 9
7 36 2
23 43 9
3 49 4
50 38 10
40 20 8
2 37 1
43 42 7
11 25 7
3 1 4
43 29 4
1 48 7
10 13 6
8 12 8
24 4 3
18 42 5
35 46 5
45 30 10
27 21 4
29 39 8
33 50 7
17 15 9
19 34 3
8 32 3
38 8 8
18 43 4
5 24 6
31 16 1
49 9 5
13 47 6
42 46 10
26 49 7
26 22 6
12 1 5
  • 0
  • 0
monkukui タイトルなし
C++
50 150
42 43 2
37 49 8
41 26 10
10 13 1
9 33 6
19 4 6
43 23 8
49 3 10
8 38 4
16 10 7
34 24 4
43 18 5
28 6 8
23 32 9
30 15 6
22 38 10
49 9 3
33 40 1
18 25 2
11 39 7
17 15 10
25 16 2
16 19 1
38 24 9
1 31 9
16 15 5
9 7 1
28 39 2
10 36 7
10 40 9
48 46 10
9 32 4
7 17 1
46 24 8
43 2 10
28 38 5
4 24 4
34 20 3
26 30 2
13 47 8
50 7 2
20 24 3
16 49 5
33 14 7
3 2 6
14 44 8
38 41 10
35 46 3
47 23 3
48 31 6
37 2 9
46 9 5
9 28 4
40 38 8
47 3 3
36 42 6
14 8 8
20 3 5
13 41 2
12 15 8
26 13 3
10 32 5
26 49 6
18 10 7
29 39 1
29 48 8
12 28 5
5 24 2
15 46 1
50 38 7
40 20 4
13 25 5
47 2 9
34 21 8
8 43 4
3 1 4
16 39 4
48 1 6
8 12 6
46 42 7
44 25 4
43 12 3
45 19 3
26 22 1
32 14 9
45 16 10
47 30 7
11 12 7
31 13 4
49 29 2
6 25 2
32 48 10
3 44 4
11 25 7
26 33 8
9 27 10
21 23 1
27 41 6
15 35 10
12 1 5
26 39 4
17 33 10
20 8 4
9 20 8
40 41 6
6 26 10
42 9 4
11 19 7
16 31 4
16 43 2
29 43 2
42 3 5
18 38 1
50 33 4
33 28 1
45 30 7
13 49 9
32 16 2
7 36 10
28 48 9
37 31 7
10 23 9
5 23 3
4 16 6
22 27 10
48 39 5
24 11 10
27 19 3
46 33 2
49 7 6
37 46 8
17 2 3
19 12 9
8 32 3
35 12 5
46 29 3
37 24 7
15 27 10
21 27 2
34 19 10
18 23 9
34 31 2
3 37 5
34 46 10
32 3 4
18 42 9
36 24 8
6 30 1
49 38 7
5 37 6
  • 0
  • 0
monkukui タイトルなし
C++
50 96
23 3 10
39 38 1
49 24 10
27 18 10
20 16 1
46 5 1
10 7 3a
33 4 1
10 40 10
17 26 3
11 29 4
37 39 4
8 36 1
12 26 8
37 25 10
9 45 1
12 26 8
22 33 7
36 44 5
22 47 4
28 48 10
31 29 3
32 39 4
42 13 6
1 40 10
38 28 5
9 22 5
48 18 1
18 48 1
26 17 3
8 6 10
11 29 4
33 9 4
28 48 10
3 32 4
9 22 5
5 46 1
25 31 2
42 5 10
31 24 1
9 15 10
46 44 5
39 28 7
31 25 2
40 1 10
25 29 1
41 21 10
25 38 10
48 30 10
38 37 7
3 12 10
21 14 10
32 14 10
4 44 7
4 44 7
28 38 5
40 10 10
4 9 9
24 49 10
45 22 6
29 24 7
50 16 10
33 45 1
35 16 1
35 20 1
45 33 1
47 22 4
6 27 2
34 27 10
3 32 4
46 44 5
24 31 1
1 43 2
1 2 10
25 11 7
43 1 2
32 37 8
19 1 10
10 17 6
17 7 2
33 4 1
23 28 2
38 39 1
32 39 4
37 25 10
32 38 8
37 39 4
35 19 10
25 24 5
6 27 2
7 26 3
28 23 2
4 45 4
20 35 1
45 9 1
14 32 10
  • 0
  • 0
monkukui タイトルなし
C++
50 96
23 3 10
39 38 1
49 24 10
27 18 10
20 16 1
46 5 1
10 7 3
33 4 1
10 40 10
17 26 3
11 29 4
37 39 4
8 36 1
12 26 8
37 25 10
9 45 1
12 26 8
22 33 7
36 44 5
22 47 4
28 48 10
31 29 3
32 39 4
42 13 6
1 40 10
38 28 5
9 22 5
48 18 1
18 48 1
26 17 3
8 6 10
11 29 4
33 9 4
28 48 10
3 32 4
9 22 5
5 46 1
25 31 2
42 5 10
31 24 1
9 15 10
46 44 5
39 28 7
31 25 2
40 1 10
25 29 1
41 21 10
25 38 10
48 30 10
38 37 7
3 12 10
21 14 10
32 14 10
4 44 7
4 44 7
28 38 5
40 10 10
4 9 9
24 49 10
45 22 6
29 24 7
50 16 10
33 45 1
35 16 1
35 20 1
45 33 1
47 22 4
6 27 2
34 27 10
3 32 4
46 44 5
24 31 1
1 43 2
1 2 10
25 11 7
43 1 2
32 37 8
19 1 10
10 17 6
17 7 2
33 4 1
23 28 2
38 39 1
32 39 4
37 25 10
32 38 8
37 39 4
35 19 10
25 24 5
6 27 2
7 26 3
28 23 2
4 45 4
20 35 1
45 9 1
14 32 10
  • 0
  • 0
monkukui タイトルなし
C++
10 47
4 2 6
2 7 2
10 9 3
2 10 1
8 9 2
8 3 4
4 8 1
2 9 4
5 10 9
7 10 1
8 6 1
4 9 1
6 4 2
10 7 1
10 1 1
5 7 9
6 9 4
2 10 1
3 4 4
8 5 1
6 7 10
7 3 1
5 3 9
7 9 3
4 1 10
2 1 1
8 4 1
5 4 1
9 7 3
3 1 8
10 3 2
8 6 1
6 5 3
4 5 1
2 3 7
4 10 5
3 6 6
9 3 4
7 3 1
8 10 8
9 4 1
4 7 4
9 5 1
8 7 6
1 9 6
5 2 9
7 1 2
  • 0
  • 0
monkukui タイトルなし
C++
20 73
10 2 5
16 10 4
15 13 9
13 9 8
20 7 4
17 3 6
5 4 3
2 19 6
6 8 1
9 15 4
6 8 1
8 4 2
8 4 2
7 12 2
20 19 3
5 8 7
10 7 1
20 10 3
16 20 1
19 10 6
20 17 2
14 3 3
3 11 10
12 7 2
10 1 6
2 1 1
13 4 10
12 9 9
15 9 4
18 8 2
9 4 1
7 17 1
5 13 4
4 5 3
2 7 8
4 18 7
3 12 1
20 19 3
3 14 3
12 18 9
4 15 10
4 9 1
5 13 4
17 20 2
19 1 2
17 19 8
17 10 1
1 19 2
14 12 9
4 6 8
15 2 5
7 17 1
19 7 10
7 3 7
2 17 10
16 1 10
5 9 6
3 12 1
16 20 1
11 18 5
16 17 3
18 8 2
17 12 3
8 9 8
15 10 9
12 10 5
18 11 5
18 3 8
6 18 4
15 2 5
7 16 5
19 16 3
20 1 8
  • 0
  • 0
anonymous タイトルなし
C++
#include <iostream>
#include <map>
using std::map;
using std::ostream;

typedef map<char, int> Plate;

ostream& operator << (ostream& os, Plate& p) {
	for (auto m_itr : p) {
		os << m_itr.first << " " << m_itr.second << std::endl;
	}
	return os;
}

/* // pointer ver.
class Dog {
	public:
	Dog(Plate& _plate, char _c) {
		plate = &_plate;
		c = _c;
		std::cout << "debug hoge" << *plate << std::endl; // debug
	}

	void bite() {
		std::cout << "debug fuga" << *plate << std::endl; // debug
		plate->at(c)--;
	}

	private:
	Plate* plate;
	char c;
};
// */

//* // ref. ver. // if you misstake something, then error message is very long and unreadable
class Dog {
	public:
	Dog(Plate& plate, char _c) : plate(plate) {
		c = _c;
		std::cout << "debug hoge" << plate << std::endl; // debug
	}

	void bite() {
		std::cout << "debug fuga" << plate << std::endl; // debug
		plate[c]--;
	}

	private:
	Plate& plate;
	char c;
};
// */

int main() {

	Plate shared_plate;
	shared_plate['p'] = 10;
	shared_plate['r'] = 10;

	Dog pochi = Dog(shared_plate, 'p');
	Dog ryo = Dog(shared_plate, 'r');

	pochi.bite();
	ryo.bite();

	std::cout << "debug " << std::endl << shared_plate << std::endl; // debug


	std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

  • 0
  • 0
あなたもコードを投稿しませんか?
投稿する
123